【问题标题】:Nginx 301 rewrites using regexNginx 301 使用正则表达式重写
【发布时间】:2014-11-01 22:21:27
【问题描述】:

我转移到一个新软件,现在需要捕获旧的 url 并将它们重写为新的。

这是一个例子:

旧网址:http://www.religiousforums.com/forum/neopagan-revival-religions-dir/19088-druid-horoscope-whats-your-sign.html 新网址:https://www.religiousforums.com/threads/druid-horoscope-whats-your-sign.19088/

我试过了,但它不起作用:

    location ~* ^/forum/[^/]+/[0-9]+-[^\.]+\.html$ {
            rewrite [^/]+/([0-9]+)-[^\.]+\.html$ /threads/$1/ last;
    }

我在这里缺少什么?我只需要新网址中的 id。文字不重要。

【问题讨论】:

    标签: redirect nginx


    【解决方案1】:

    您的捕获组错误,您正在捕获数字。

    location ~* ^/forum/[^/]+/[0-9]+-[^.]+\.html$ {
        rewrite ^/forum/[^/]+/([0-9]+)-([^.]+)\.html$ /threads/$2.$1/ last;
    }
    

    【讨论】:

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