Bri*_*kau 7 mod-rewrite encoding url-rewriting
我需要采用标准的传入URL并重写它们以将其重定向到单个页面上的特定锚点(传入的html页面名称成为锚点名称).例如,规则是这样的:
RewriteRule ^files/([a-zA-Z0-9\-_]+)\.html$ /test.html#$1 [R]
Run Code Online (Sandbox Code Playgroud)
所以这个网址:
http://foo.com/files/bar.html
Run Code Online (Sandbox Code Playgroud)
...会成为:
http://foo.com/test.html#bar
Run Code Online (Sandbox Code Playgroud)
规则本身工作正常,但#字符在浏览器地址栏中编码为:
http://foo.com/test.html%23bar
Run Code Online (Sandbox Code Playgroud)
这当然不能作为锚点正常工作.是否有一种方法在.htaccess中强制它不对哈希进行编码?我也试过逃避它,\#但这没有任何区别.
Pat*_*Pat 10
尝试规则中的noescape(NE)标志:
RewriteRule ^files/([a-zA-Z0-9\-_]+)\.html$ /test.html#$1 [NE, R]
Run Code Online (Sandbox Code Playgroud)
使用NE或无逃脱标志:
RewriteRule ^files/([a-zA-Z0-9\-_]+)\.html$ /test.html#$1 [NE,R]