如何重定向到包含锚(#)的URL? [英] How to Redirect to a url containing an anchor (#)?
本文介绍了如何重定向到包含锚(#)的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要采用标准的传入URL,并且重写将它们重定向到单个页面上的特定锚点(传入的html页面名称成为锚点名称)。例如,规则如下:
I need to take standard incoming urls and rewrite redirect them to target specific anchors on a single page (incoming html page name becomes the anchor name). E.g., the rule would be like this:
RewriteRule ^files/([a-zA-Z0-9\-_]+)\.html$ /test.html#$1 [R]
所以这个url:
http://foo.com/files/bar.html
...将成为:
http://foo.com/test.html#bar
规则本身工作正常,但#字符被编码在浏览器地址栏中:
The rule itself works fine, but the # character gets encoded in the browser address bar to:
http://foo.com/test.html%23bar
当然不能正常工作。在.htaccess中有没有办法强制它不对哈希进行编码?我也尝试像 \#
一样转义,但没有什么区别。
which of course does not work correctly as an anchor. Is there a way in .htaccess to force it not to encode the hash? I also tried escaping it like \#
but that makes no difference.
推荐答案
RewriteRule ^files/([a-zA-Z0-9\-_]+)\.html$ /test.html#$1 [NE, R]
这篇关于如何重定向到包含锚(#)的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文