【问题标题】:nginx location rewrite anything after / to rootnginx位置在/之后重写任何内容到root
【发布时间】:2018-07-11 21:02:20
【问题描述】:

假设我有 example.com,我想在 / 之后重写任何内容到 root,即 example.com/one/two?whatever=foo 应该回到 example.com

我尝试了以下方法:

location = / {
    index  index.html;
}

location / {
    rewrite ^ / permanent;
}

但这给了我太多重定向错误。我可以使用正则表达式来指定所有允许/不允许的字符,但这会使其太丑/长/复杂。

为什么完全匹配不能区分?

【问题讨论】:

    标签: nginx url-rewriting


    【解决方案1】:

    您使用index 指令执行从//index.html 的内部重写。详情请见this document

    nginx 然后重新开始搜索匹配的location,这会导致循环。

    您可以为/index.html URI 添加完全匹配,例如:

    location = /index.html { }
    

    如果index.html 拉取本地资源(例如 css、js、图像),您还需要专门处理这些 URI。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-21
      • 2013-12-16
      • 1970-01-01
      • 2017-05-19
      • 2014-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多