【问题标题】:301 redirect to domain with # in the URL301 重定向到 URL 中带有 # 的域
【发布时间】:2019-08-25 10:16:13
【问题描述】:

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

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 的文字表示?如果这是不正确的,我需要做任何转义吗?

提前感谢您的帮助。

【问题讨论】:

    标签: regex apache redirect url-redirection http-status-code-301


    【解决方案1】:

    使用NE 选项避免编码:

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

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

    【讨论】:

      猜你喜欢
      • 2014-12-04
      • 2013-10-05
      • 2013-07-02
      • 2012-01-19
      • 2013-09-26
      • 1970-01-01
      • 2016-12-07
      • 2017-08-14
      • 2022-01-01
      相关资源
      最近更新 更多