【问题标题】:How to rewrite a path with a '#' sign in nginx如何在 nginx 中用“#”符号重写路径
【发布时间】:2019-01-13 16:28:13
【问题描述】:

我有www.example.com/aaawww.example.com/aaa#bbb 格式的路径,我想将其重定向到www.example.com

我试过了:

if ($uri ~ ^/(.*)(#.*)?) {
    rewrite ^/(.*)(#.*)? / permanent;
}

我什至尝试过#。它似乎进入了 if 块。它替换了第一部分,但第二部分附加到 url。新的 url 变成了www.example.com/#bbb

【问题讨论】:

    标签: regex nginx nginx-location


    【解决方案1】:

    URL 中的哈希(URL 中# 之后的部分)不是设计为在 HTTP 请求中发送的。因此,nginx对此无能为力。当用户访问http://example.com/#aaa时,nginx只看到对http://example.com的请求

    一种可能的解决方法是在前端使用 Javascript 从 URL 中删除哈希。另一个 Stack Overflow 问题描述了如何做到这一点:https://stackoverflow.com/a/4508751/3474615

    【讨论】:

    • 谢谢伙计,那个链接真的很有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-12
    • 1970-01-01
    • 1970-01-01
    • 2019-08-27
    • 2019-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多