ProxyPass和ProxyPassReverse可以在htaccess中工作吗?

Joe*_*her 37 apache .htaccess

我以前从未设置代理.我正在使用共享主机,所以要设置Apache指令,我需要使用.htaccess.我可以使用.htaccess做下面的事吗?任何限制?

ProxyRequests Off
ProxyPass /img/ http://internal.example.com/img/
ProxyPass /app/ http://internal.example.com/app/

ProxyPassReverse / http://internal.example.com/
Run Code Online (Sandbox Code Playgroud)

Jon*_*Lin 39

您不能ProxyPass在htaccess文件中使用a.文档说它仅适用于上下文:

上下文:服务器配置,虚拟主机,目录

不包括htaccess(你不能<Directory>在htaccess中阻止).但是,您可以使用a ProxyPassReverse在内部重写导致重定向的代理请求的Location字段.你只需要使用mod_rewrite的P标志来代替ProxyPass.所以类似于:

RewriteEngine On
RewriteRule ^/?img/(.*)$ http://internal.example.com/img/$1 [L,P]
RewriteRule ^/?app/(.*)$ http://internal.example.com/app/$1 [L,P]

ProxyPassReverse / http://internal.example.com/
Run Code Online (Sandbox Code Playgroud)

为了清楚起见,您不能使用ProxyPass ProxyPassReverse在htaccess文件中,但您可以使用ProxyPassReversemod_rewrite规则来使用该P标志.

  • 你也不能在htaccess中使用`ProxyPassReverse`(http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypassreverse) (22认同)
  • 当我在 OSX Server 3.1.1 上的 htaccess 中使用 ProxyPassReverse 时,我收到以下消息“此处不允许 ProxyPassReverse” (3认同)
  • 我在OSX 10.9上,我也不允许在这里使用ProxyPassReverse. (2认同)
  • 我在 .htaccess 中使用它来修复重定向:`Header edit Location ^http://internal\.example\.com/(.*) http://example.com/$1` (2认同)
  • 我被困了几天才能使代理工作,但这确实有所帮助。最后不需要`ProxyPassReverse / http:// internal.example.com /`部分 (2认同)