【问题标题】:Redirect 2 urls (%20) to one in nginx将 2 个 url (%20) 重定向到 nginx 中的一个
【发布时间】:2021-10-26 05:39:43
【问题描述】:

我有这个我无法解决的问题。我有一个 nginx 服务器,我必须进行这种类型的重定向。

http://midomain.com/xxxx/xxxx/http://wikipedia.com/xx --> http://midomain.com/yyyy

因为我有两个带空格的网址,所以没有办法让它工作。

我尝试了多种方法。

rewrite ^/xxxx/xxxx/\ http://wikipedia.com/xx http://midomain.com/yyyy permanent;
rewrite "^/xxxx/xxxx/\ http://wikipedia.com/xx" http://midomain.com/yyyy permanent;
rewrite ^/xxxx/xxxx/%20http://wikipedia.com/xx http://midomain.com/yyyy permanent;
rewrite "^/xxxx/xxxx/%20http://wikipedia.com/xx" http://midomain.com/yyyy permanent;
rewrite ^/xxxx/xxxx/\ http://wikipedia.com/xx/$ http://midomain.com/yyyy permanent;
rewrite "^/xxxx/xxxx/\ http://wikipedia.com/xx/$" http://midomain.com/yyyy permanent;
rewrite ^/xxxx/xxxx/%20http://wikipedia.com/xx/$ http://midomain.com/yyyy permanent;

我不知道我是不是做错了什么。

【问题讨论】:

    标签: nginx url redirect spaces


    【解决方案1】:

    Nginx 在通过 rewrite 处理 URI 之前对其进行规范化。 %20 被解析为文字空格字符,连续的/ 字符被单个/ 替换。正是最后一点给你带来了问题。

    例如:

    rewrite "^/xxxx/xxxx/ http:/wikipedia\.com/xx$" http://midomain.com/yyyy permanent;
    

    【讨论】:

      猜你喜欢
      • 2014-01-20
      • 1970-01-01
      • 2020-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-28
      • 2020-09-05
      • 1970-01-01
      相关资源
      最近更新 更多