不改变URL重定向Apache

6

我想将一个URL重定向到另一个URL,但不改变浏览器中的URL。

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

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


我非常确定那是不可能的。这就像试图告诉出租车司机你要去21号假街,但实际上你想去38号真正的街道一样。地址应该将您重定向到指定的地址。如果我更好地理解了您的问题,我猜您可以看一下URL掩盖http://blog.clickmeter.com/link-cloaking-vs-url-masking/。 - Master Yoda
@KyleT 这一点根本不难... 有几种方法可以做到。 - arco444
@arco444 是的,我刚刚弄清楚 OP 在问什么。我建议使用 URL 掩盖。 - Master Yoda
2个回答

7
您可以使用RewriteRule
RewriteEngine On
RewriteRule /abc/(.*)\.xml$ /abc/xyz/index.htm?file=$1 [L]

请确保您已启用mod_rewrite 并将其放置在您的VirtualHost配置文件中或在您的DocumentRoot中的.htaccess文件中。


@acro444 感谢您的快速回复。我只是将 L 标志替换为 P,它完美地工作了。 RewriteEngine On RewriteRule /abc/(.*).xml$ /abc/xyz/index.htm?file=$1 [P] - Constantine
肯定有帮助。 - Constantine
我的意思是你应该接受这个答案!请查看此链接:http://stackoverflow.com/help/someone-answers - arco444

0

就像Constantine在已接受的解决方案中发布的一样,[P]标志是危险的,因为它将服务器转换为代理。

请参见[这个]: 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.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接