如何在 url 中使用 # 进行 .htaccess 301 重定向

How to do .htaccess 301 redirect with # in url

我需要在htaccess 中编写301 重定向代码。 我试过的。

RewriteRule ^old-url-shoes/$  new-url-shoes-abc/#div-id-shoes [R=301,NC,L] 

此代码正在创建此 url

new-url-shoes-abc/%23div-id-shoes

正在用“%23”替换“#”。

请提出解决方案。

能否请您尝试以下一次,使用显示的示例编写和测试。 请在测试您的 URL 之前清除您的浏览器缓存。

RewriteRule ^old-url-shoes/$  new-url-shoes-abc/#div-id-shoes [R=301,NC,NE,L]

来自文档:

NE|noescape By default, special characters, such as & and ?, for example, will be converted to their hexcode equivalent. Using the [NE] flag prevents that from happening.

此外,作为附加建议,请使用 ^old-url-shoes/?$ ?,这样它将涵盖 url 在规则中以斜线结尾或不以斜线结尾的情况。