Apache RewriteRule修改request_uri

时间:2013-01-04 15:18:59

标签: apache mod-rewrite

根据条件,我希望Apache更改REQUEST_URI,然后将新的REQUEST_URI代理到不同的Web服务器

这应该是相当有用的,但是,互联网上的所有例子都没有给我任何结果。

例如我的网址:http://my.domain.com/otherserver/dir2/page1.html?param1=true%param2=10 基于REQUEST_URI的开头,我想将REQUEST_URI修改为/dir2/page1.html?param1=true%param2=10并将其传递给其他网络服务器

例如

RewriteCond %{REQUEST_URI} ^/otherserver
RewriteRule ^(.*) ^/otherserver / [N]
RewriteRule ^(.*)$ http://localhost:8080%{REQUEST_URI} [P]

然而,这并没有产生预期的结果。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我建议你尝试不同的方式,例如使用mod_proxy代替P标记mod_rewrite(请参阅the mod_rewrite documentation for the P flag,其中包含“避免此标记,并尽可能选择[mod_proxy指令”,还有When Not To Use Rewrite)。

如果我理解正确,您想要的行为是“对于表单^/otherserver(.*)的所有请求,请求将请求代理到http://localhost:8080$1”。 When Not To Use Rewrite page建议可以将此作为

ProxyPass /otherserver http://localhost:8080/

...但在接受我的话之前在the mod_proxy documentation确认一下。

相关问题