这里有一个关于 mod_rewrite 的小但令人困惑的 htaccess 问题。 我们需要转发: http://www.mydomain.com/ladies-boots/?shoesize=43&calfwidth=K 到 http://www.mydomain.com/ladies-boots/#nogo&somevar=1&shoesize=43&calfwidth=K
我们的代码(感谢另一篇 Stackoverflow 帖子)是:
RewriteCond %{QUERY_STRING} ^shoesize=([0-9]+)\&calfwidth=([A-Z])$
RewriteRule ^ladies-boots/$ http://www.mydomain.com/ladies-boots/#nogo&somevar=1&shoesize=%1&calfwidth=%2? [R=301,L]
上面的方法效果很好,除了 hash # 标签被 Apache 转义,Apache 将 URL 写为 %23 而不是 #。
有什么办法可以解决这个问题吗?我确实需要哈希标签来实现某些 Javascript/非 SE 友好的功能,并且如果没有有效的哈希标签,上述 URL 将无法使用。
非常感谢!
最佳答案
The above works great, except the hash # tag is escaped by Apache, which writes the URL as with a %23 instead of the #.
如果您在方括号内使用 NE
标志,则可以使哈希标记不转义:[R=301,L,NE]
关于.htaccess - htaccess mod 重写 - 我可以将我的 URL 转发到另一个带有哈希标签的 URL 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11740047/