【问题标题】:nginx - rewrite rule for URL with different cases and encoded spacesnginx - 使用不同大小写和编码空格的 URL 重写规则
【发布时间】:2019-08-06 15:39:35
【问题描述】:

部署全新版本的门户我必须添加一些“旧版”重写,以便将所有过去的文档链接重定向到新版本。

其中一些旧链接就像

http://sitename.com/media/pdf/MIXED%20FIL_E_Name_With%20spaces_and%20stuff-e324a.pdf

而他们的新路径是

https://sitename.it/app/uploads/2019/03/mixed-fil_e_name-with-spaces_and-stuff-e324a.pdf.

我尝试了以下重写,但无济于事。

rewrite ^/media/pdf/MIXED%20FIL_E_Name_With%20spaces_and%20stuff-e324a.pdf(.*) /app/uploads/2019/03/mixed-fil_e_name-with-spaces_and-stuff-e324a.pdf permanent;

rewrite ^/media/pdf/MIXED\%20FIL_E_Name_With\%20spaces_and\%20stuff-e324a.pdf(.*) /app/uploads/2019/03/mixed-fil_e_name-with-spaces_and-stuff-e324a.pdf permanent;

rewrite ^/media/pdf/MIXED\\\%20FIL_E_Name_With\\\%20spaces_and\\\%20stuff-e324a.pdf(.*) /app/uploads/2019/03/mixed-fil_e_name-with-spaces_and-stuff-e324a.pdf permanent;

我错过了什么?

【问题讨论】:

    标签: regex nginx redirect url-rewriting


    【解决方案1】:

    rewritelocation 指令使用规范化的 URI。保留字符已被解码。使用文字空格代替%20,但将表达式括在引号中。

    例如:

    rewrite "^/media/pdf/MIXED FIL_E_Name_With spaces_and stuff-e324a.pdf" /app/uploads/2019/03/mixed-fil_e_name-with-spaces_and-stuff-e324a.pdf permanent;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-28
      • 2013-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多