首页 > 解决方案 > 301 重定向到 URL 中带有 # 的域

问题描述

我目前正在尝试重定向以下内容:

bar.com/foo ====> bar.com/bar.html#/#

我的重定向规则如下:

RewriteEngine On
RewriteRule ^/foo$  bar.com/bar.html#/#  [R=301,L,NC]

这是我运行测试 curl 时的输出:

301 http://bar.com/foo ======>
https://bar.com/bar.html%23/%23

它返回一个 301 HTTP 响应;但是,这些 %23 字符是表示重定向后 # 将出现在 URL 中的编码指示,还是 URL 的文字表示?如果这是不正确的,我需要做任何转义吗?

在此先感谢您的帮助。

标签: regexapacheredirecturl-redirectionhttp-status-code-301

解决方案


使用NE选项避免编码:

RewriteEngine On

RewriteRule ^/?foo/?$ /bar.html#/# [R=301,L,NC,NE]

确保在新浏览器中测试它以避免旧缓存。


推荐阅读