Apache重写到某个位置
我们有一个web应用程序,它可以处理不同的URL格式,并以不同的格式返回相同的内容Apache重写到某个位置,apache,rewrite,Apache,Rewrite,我们有一个web应用程序,它可以处理不同的URL格式,并以不同的格式返回相同的内容 /dosomething /foo/dosomething (returns mobile content) /bar/dosomething (returns html for a browser) 请参见下面的虚拟主机示例 对于Apache2.2,我使用重写规则重定向到“/baz/”位置,该位置的功能与我预期的一样 重写规则上的“PT”标志将URI传递回Apache,并允许我们从“baz”位置提供内容 &l
/dosomething
/foo/dosomething (returns mobile content)
/bar/dosomething (returns html for a browser)
请参见下面的虚拟主机示例
对于Apache2.2,我使用重写规则重定向到“/baz/”位置,该位置的功能与我预期的一样
重写规则上的“PT”标志将URI传递回Apache,并允许我们从“baz”位置提供内容
<VirtualHost *:80>
ServerName www.foobarbaz.net
RewriteEngine On
#Block requests for favicon
RewriteRule ^/favicon.ico$ - [F]
# If the requested URI is NOT located in bar or foo
# Prepend an /baz to everything that does not already starts with it
# and force the result to be handled by the next URI-handler ([PT])
RewriteCond %{REQUEST_URI} !^/bar/.*$
RewriteCond %{REQUEST_URI} !^/foo/.*$
RewriteRule ^/(.*) /baz/$1 [PT,QSA]
<Location "/baz/">
RequestHeader append ABC-Request-Origin "/baz"
ProxyPass ajp://localhost:8009/webapp/
ProxyPassReverse /
ProxyPassReverseCookiePath /webapp /
</Location>
<Location "/bar/">
RequestHeader append ABC-Request-Origin "/bar"
ProxyPass ajp://localhost:8009/webapp/
ProxyPassReverse /
ProxyPassReverseCookiePath /webapp /bar/
</Location>
<Location "/foo/">
RequestHeader append ABC-Request-Origin "/foo"
ProxyPass ajp://localhost:8009/webapp/
ProxyPassReverse /
ProxyPassReverseCookiePath /webapp /foo/
</Location>
</VirtualHost>
服务器名www.foobarbaz.net
重新启动发动机
#阻止对favicon的请求
重写规则^/favicon.ico$-[F]
#如果请求的URI不在bar或foo中
#将an/baz前置到尚未开始的所有内容
#并强制由下一个URI处理程序([PT])处理结果
重写cond%{REQUEST_URI}^/巴/*$
重写cond%{REQUEST_URI}^/foo/*$
重写规则^/(.*)/baz/$1[PT,QSA]
RequestHeader附加ABC请求源“/baz”
ProxyPassajp://localhost:8009/webapp/
ProxyPassReverse/
ProxyPassReverseCookiePath/webapp/
RequestHeader追加ABC请求来源“/bar”
ProxyPassajp://localhost:8009/webapp/
ProxyPassReverse/
ProxyPassReverseCookiePath/webapp/bar/
RequestHeader追加ABC请求源“/foo”
ProxyPassajp://localhost:8009/webapp/
ProxyPassReverse/
ProxyPassReverseCookiePath/webapp/foo/
对于Apache2.4.12,重写规则的工作方式不同,Apache会尝试在文件系统上查找内容。Apache查找不存在的“baz”目录
我尝试添加另一个位置“/”并删除重写规则(见下文)
文件指出,对于重叠位置,最不具体的位置应优先
这适用于“/”,但不适用于“/foo/”或“/bar”。似乎始终使用“/”,并且向p.roxy发出的请求中始终包含“foo”和“bar”
<VirtualHost *:80>
ServerName www.foobarbaz.net
<Location "/">
RequestHeader append ABC-Request-Origin "/baz"
ProxyPass ajp://localhost:8009/webapp/
ProxyPassReverse /
ProxyPassReverseCookiePath /webapp /
</Location>
<Location "/bar/">
RequestHeader append ABC-Request-Origin "/bar"
ProxyPass ajp://localhost:8009/webapp/
ProxyPassReverse /
ProxyPassReverseCookiePath /webapp /bar/
</Location>
<Location "/foo/">
RequestHeader append ABC-Request-Origin "/foo"
ProxyPass ajp://localhost:8009/webapp/
ProxyPassReverse /
ProxyPassReverseCookiePath /webapp /foo/
</Location>
</VirtualHost>
服务器名www.foobarbaz.net
RequestHeader附加ABC请求源“/baz”
ProxyPassajp://localhost:8009/webapp/
ProxyPassReverse/
ProxyPassReverseCookiePath/webapp/
RequestHeader追加ABC请求来源“/bar”
ProxyPassajp://localhost:8009/webapp/
ProxyPassReverse/
ProxyPassReverseCookiePath/webapp/bar/
RequestHeader追加ABC请求源“/foo”
ProxyPassajp://localhost:8009/webapp/
ProxyPassReverse/
ProxyPassReverseCookiePath/webapp/foo/
是否有人对如何改进此设置提出建议?或关于以不同于“/foo”或“/bar”的方式处理请求的建议
谢谢你的帮助
Jim首先使用位置“/”似乎确实正确地使用了“/”、“/foo”和“/bar”的位置。我确实存在与在应用程序中构建链接相关的其他问题,但我不认为这是Apache问题