如何重写经过 apaches mod_proxy 的 url
我已经使用 mod_proxy 和 mod_proxy_http 将我的 apache 2.2 服务器配置为简单的转发代理。
当客户端请求以下格式的 URL 时:
http://specific.host.com/specific?specificarg1=(.+)&specificarg2=(.+)&specificarg3=specificvalue
以重写的形式请求,其中 specicarg1 和 specicarg2 的值被我的服务器配置中定义的值替换。
也可以不使用正则表达式,而是将特定的 url 重写为另一个特定的 url,但我更喜欢使用正则表达式匹配。
因此,在阅读了 mod_rewrite、mod_proxy 等文档之后,我尝试了类似以下的操作来使某种重写工作:
RewriteRule .* http://www.google.com/ [P,L
]
就像服务器配置中的那样,通过代理冲浪时没有任何内容被重写,
<VirtualHost *:80>
ServerName domain-i-tried-to-surf-to.com
`RewriteRule .* http://www.google.com/ [P,L]
</VirtualHost>
不运气也不
ProxyPass(Reverse) / http://www.google.com
ProxyPass(Reverse) /path/i/tried/to/surf/to http://www.google.com
运气那也
ProxyRemote * http://www.google.com
没有运气好吧,
我也尝试将重写规则放入 proxymatch 指令中,但我只是无法重写 url。有人能指出我正确的方向吗?
I have configured my apache 2.2 server as a simple forward proxy using mod_proxy and mod_proxy_http.
When the client requests a URL of the following format:
http://specific.host.com/specific?specificarg1=(.+)&specificarg2=(.+)&specificarg3=specificvalue
to be requested in a rewritten form where the values for specificarg1 and specificarg2 get replaced by values defined in my server config.
It would be also possible not to use regex but to rewrite a specific url to another specific url, but i would prefer with regex matching.
So after reading the documentsations for mod_rewrite, mod_proxy and so I tried something like the following to get some sort of rewrite working at all:
RewriteRule .* http://www.google.com/ [P,L
]
just like that in the server config, nothing gets rewriten when surfing over the proxy
<VirtualHost *:80>
ServerName domain-i-tried-to-surf-to.com
`RewriteRule .* http://www.google.com/ [P,L]
</VirtualHost>
no luck either
ProxyPass(Reverse) / http://www.google.com
ProxyPass(Reverse) /path/i/tried/to/surf/to http://www.google.com
no luck with that too
ProxyRemote * http://www.google.com
no luck as well
I also tried to put rewrite rules into proxymatch directives but I am just unable to rewrite a url. Can somebody point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您首先需要在最开始添加一个
RewriteEngine on
语句,甚至让 mod_rewrite 来处理任何规则。You first need to add a
RewriteEngine on
statement at the very beginning to even get mod_rewrite to process any rules.