【发布时间】:2015-07-23 21:27:56
【问题描述】:
我正在运行 Apache 2.4 并使用 mod_rewrite 来实现以下目标 - 我需要代理几个不同的内部站点,以便它们看起来托管在同一台服务器上。例如,我希望这样做的方式是使用http://myserver/osnews 形式的 URL
这将代理来自www.osnews.com 和http://myserver/slashdot 的内容,这将代理来自www.slashdot.org 的内容。我在我的 apache conf 文件中定义了以下重写规则:
RewriteCond %{REQUEST_URI} ^/osnews(/?.*) [NC]
RewriteRule ^/osnews(.*) http://www.osnews.com$1 [P]
RewriteCond %{REQUEST_URI} ^/slshdot(/?.*) [NC]
RewriteRule ^/osnews(.*) http://www.slashdot.org$1 [P]
问题在于这会破坏代理站点中的所有样式表和图像。我认为这是因为重写的 URL 的形式是 http://myserver/story/28554/Russia_unveils_homegrown_PC_microprocessor_chips 而不是 http://myserver/osnews/story/28554/Russia_unveils_homegrown_PC_microprocessor_chips
相反,如果我尝试这样的事情,它工作得很好(我没有将网站作为原始网址的一部分,所以http://myserver 将只是代理到http://www.osnews.com):
RewriteCond %{HTTP_HOST} ^myserver$ [NC]
RewriteRule ^ http://www.osnews.com%{REQUEST_URI} [P]
所以,我需要指导的是如何在代理从http://osnews.com/some-resource 返回后保留 URL http://mysite/osnews/some-resource
谢谢!
【问题讨论】:
标签: mod-rewrite url-rewriting apache2.4