用 # 重写 url
如何用 # 重写 url?例如 http://www.example.com/index.php#test
在我当前的我有 .htaccess 文件:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^([^/.]+)/?$ $1.php [L] # rewrite without query string parameters
RewriteRule ^([^/.]+)/([^/.]+)/?$ $1.php\#$2 [L] # one name string parameter
这将重写一个网址,例如 http://www.example.com/index/测试,以便您被定向到该页面,但不会带您到相关的标签如 http://www.example.com/index#test 或 http://www.example.com/index.php#test 会。
How do you rewrite a url with a # in? e.g. http://www.example.com/index.php#test
In my current .htaccess file I have:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^([^/.]+)/?$ $1.php [L] # rewrite without query string parameters
RewriteRule ^([^/.]+)/([^/.]+)/?$ $1.php\#$2 [L] # one name string parameter
This would rewrite a url such as http://www.example.com/index/test so you are directed to the page, but not take you to the relevant tag like http://www.example.com/index#test or http://www.example.com/index.php#test would.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用类似这样的方法将一个 url 重定向到另一个末尾带有哈希值的 URL:
注意: #(及其后面的任何内容)不是对服务器的实际 HTTP 请求的一部分。
因此您无法在 .htaccess 中引用它或获取哈希值。
您必须使用例如 Javascript 来访问散列后的值!
I use something like this to redirect an url to another with a hash at the end:
Note: The # (and anything after it) is not part of the actual HTTP request to the server.
So you can't refer to it or get the hash value in you .htaccess.
You have to use e.g. Javascript to acces values after the hash!