NGinxredirect规则

我需要在nginx上redirect特定的path,但无法find方法:)特别是redirect301这个url

http://www.domain.com/c/Integratori-di-Proteine/Universal-.html http://www.domain.com/c/Integratori-Aminoacidi/+Watt.html 

分别

 http://www.domain.com/c/Integratori-di-Proteine/ http://www.domain.com/c/Integratori-Aminoacidi/ 

我试过这个没成功

 location ~ ^/c/(.+)/(.+)\.html { rewrite ^ http://www.domain.com/$1/; } 

谢谢

您的位置块缺lesspermanent属性。 这应该工作:

 location ~ ^/c/(?<section>[^/]+)/.+\.html$ { rewrite ^ http://www.domain.com/c/$section/ permanent; } 

我也从正则expression式中删除了第二个捕获组,因为它不是必需的。 我还在正则expression式中添加了string标识符的结尾,以便像http://www.domain.com/c/Integratori-di-Proteine/Universal-.html1234这样的URL不会导致redirect,而是导致404页面。

编辑:改变捕获,以便它被捕获到一个命名的variables,也改变了正则expression式模式。