如何重写经过 apaches mod_proxy 的 url

发布于 2024-11-14 00:56:06 字数 1050 浏览 5 评论 0原文

我已经使用 mod_proxy 和 mod_proxy_http 将我的 apache 2.2 服务器配置为简单的转发代理。

当客户端请求以下格式的 URL 时:

http://specific.host.com/specific?specificarg1=(.+)&specificarg2=(.+)&specificarg3=specificvalue

以重写的形式请求,其中 specicarg1specicarg2 的值被我的服务器配置中定义的值替换。

也可以不使用正则表达式,而是将特定的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘心安 2024-11-21 00:56:06

您首先需要在最开始添加一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文