【问题标题】:Apache rewrite rule for a destination containing a hash mark包含哈希标记的目标的 Apache 重写规则
【发布时间】:2012-04-17 02:13:15
【问题描述】:

我正在尝试在目的地包含片段标识符部分的情况下发出重定向。 我试过这条规则:

RewriteRule   ^/foo/bar/([^/]+)/(.*)$  /cgi/script#foobar::$1.$2  [R,L]

但是# 被转换为%23 并且Web 应用程序无法正确解析此URL。如何强制 apache 保留 # 字符?

【问题讨论】:

    标签: apache mod-rewrite fragment-identifier


    【解决方案1】:

    找到的解决方案:有一个不使用 mod_rewrite 转义 url 的选项:

    https://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_ne

    添加 [NE] 标志解决了问题。

    【讨论】:

    • 有没有办法追加查询字符串?使用这种方法我得到/myUrl?123 重定向到/newUrl#hash?123。我知道有QSA 标志,但我需要找到相反的。
    • @SimonEast 您在 Apache 2.4 上有 QSD 标志。或者只是在RewriteRule 替换的末尾附加一个?
    猜你喜欢
    • 1970-01-01
    • 2014-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 2012-05-26
    相关资源
    最近更新 更多