【发布时间】:2020-10-26 17:01:22
【问题描述】:
我知道这个问题与本网站上的其他问题相似。我花了几天时间阅读这些帖子并尝试不同的方法。没有一个有效。
我正在尝试使用 Apache 代理服务器将特定 URL 映射到新 URL。我在本地网络上有一个专用设备(黑匣子),它可以调用 original.remoteHost1.com。当 Black Box 请求服务时,我希望使用此本地网络上的 Apache 代理服务器来替换 new.remotehost2.com 为 original.remoteHost1.com。我可以将 Black Box 配置为指向代理服务器,但 Black Box 没有公开一个接口来更改其 HTTP 服务请求的目标主机。
Black Box 只提出两个非常具体的请求:
-
http://original.remoteHost1.com/rectrack/file_name.php?data_1=text_string_1
-
http://original.remoteHost1.com/rectrack/file_name.php?data_1=text_string_1&data_2=text_string_2
我想改成:
-
http://new.remotehost2.com/rectrack/file_name.php?data_1=text_string_1
-
http://new.remotehost2.com/rectrack/file_name.php?data_1=text_string_1&data_2=text_string_2
作为代理,Apache 服务器接受黑盒请求并将它们转发到 original.remoteHost1.com。我希望我能够使用 httpd.conf 中的 rewriteRule 将 original.remoteHost1.com 更改为 new.remotehost.com,但我无法让这个看似简单的功能起作用。
我已尝试使用以下 rewriteRule(以及许多变体)将 new.remotehost.com 替换为 original.host.com,但我似乎无法让 Apache 实际进行替换:
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine on
RewriteCond %{HTTP_HOST} original.remoteHost1.com
RewriteRule ^(.*) http://new.remotehost2.com/$1 [P]
有没有人知道为什么新的 URL 没有代替原来的 URL?
【问题讨论】:
标签: mod-rewrite proxy