如何重定向到包含锚点 (#) 的 url? [英] How to Redirect to a url containing an anchor (#)?

查看:38
本文介绍了如何重定向到包含锚点 (#) 的 url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要采用标准的传入 url 并 rewrite 将它们重定向到单个页面上的特定锚点(传入的 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]

所以这个网址:

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.

推荐答案

试试你的规则中的 noescape (NE) 标志:

Try the noescape (NE) flag in your rule:

RewriteRule ^files/([a-zA-Z0-9-_]+).html$ /test.html#$1 [NE, R]

这篇关于如何重定向到包含锚点 (#) 的 url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆