Nginx 301使用正则expression式重写

我转移到一个新的软件,现在需要赶上旧的url,并重新写入新的。

这里是一个例子:

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

我试过,但它不工作:

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

我在这里错过了什么? 我只需要在新的urlID。 文本并不重要。

更新:不清楚你想要做什么

如果你的意思是你想从这两个url提供相同的内容,那么你正在做内容重复 ,这是一个非常糟糕的主意。 现在要从旧的URL正确地redirect到新的,你必须设置:

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

或者简单地把它放在一个普通的位置块中:

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

编辑:这工作:

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