![如何在apache的反向代理配置中将一个url重写为外部域](https://linux22.com/image/713290/%E5%A6%82%E4%BD%95%E5%9C%A8apache%E7%9A%84%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%B0%86%E4%B8%80%E4%B8%AAurl%E9%87%8D%E5%86%99%E4%B8%BA%E5%A4%96%E9%83%A8%E5%9F%9F.png)
我有这样的配置
<VirtualHost *:80>
ProxyPreserveHost Off
ProxyRequests Off
ServerName mooo.com
ServerAlias www.mooo.com
ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/
RewriteEngine on
RewriteRule "^/foo\.html$" "/admin/" [PT]
</VirtualHost>
这很好用。现在我想重写foo.html
到其他外部域,例如当用户打开时,example.com/foo.html
我需要重定向到服务器example.org
。为此,我尝试了
RewriteRule "^/foo\.html$" "http://example.com" [PT]
但那不起作用。我该如何进行重定向?
答案1
您可以尝试以下重写规则来代理具有外部域的页面。
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/foo.html$
RewriteRule ^(.*)$ http://www.example.com/ [P]