重定向而不更改URL Apache

时间:2015-02-03 12:08:27

标签: apache redirect

我想在不更改浏览器网址的情况下将一个网址重定向到另一个网址

www.example.com/abc /(.*)。xml应该重定向到www.example.com/abc/xyz/index.htm?file=$1

但浏览器应显示www.example.com/abc /(.*).xml

2 个答案:

答案 0 :(得分:6)

您可以使用RewriteRule

RewriteEngine On
RewriteRule /abc/(.*)\.xml$ /abc/xyz/index.htm?file=$1 [L]

确保您已启用mod_rewrite并将其放入VirtualHost配置或.htaccess

中的DocumentRoot文件中

答案 1 :(得分:0)

由于Constantine在接受的解决方案上发布,[P]标志很危险,因为它将服务器转换为代理。

见[this]:https://serverfault.com/questions/214512/redirect-change-urls-or-redirect-http-to-https-in-apache-everything-you-ever?noredirect=1&lq=1

P = Proxy. Forces the rule to be handled by mod_proxy. Transparently provide content from other servers, because your web-server fetches it and re-serves it. This is a dangerous flag, as a poorly written one will turn your web-server into an open-proxy and That is Bad.