Nginx Rewite – 匹配结束Url不工作

试图redirect像这样的url:

http://example.com/vehicles/cars/author/xyz http://example.com/plane/author/xyz 

对这些:

 http://example.com/profile/xyz 

我试过这个Nginx Rewrite,但是它没有拿起匹配和redirect:

 rewrite ^/author/(.*)$ http://example.com/profile/$1 last; 

我在这里错了什么?

^/author/(*)$表示以/author/开头。 您要重写的URL不以/author/开头。 你需要这样的东西:

 rewrite ^/.*/author/(.*)$ http://example.com/profile/$1 last; 

但是我认为这样更好,可能更健壮:

 rewrite /author/([^/]+)/?$ http://example.com/profile/$1 last;