Nginx redirect one path to another

Direct quote from Pitfalls and Common Mistakes: Taxing Rewrites: By using the return directive we can completely avoid evaluation of regular expression. Please use return instead of rewrite for permanent redirects. Here’s my approach to this use-case… location = /content/unique-page-name { return 301 /new-name/unique-page-name; }

Nginx Redirect via Proxy, Rewrite and Preserve URL

First, you shouldn’t use root directive inside the location block, it is a bad practice. In this case it doesn’t matter though. Try adding a second location block: location ~ /some/path/(?<section>.+)/index.html { proxy_pass http://192.168.1.24/$section/index.html; proxy_set_header Host $host; } This captures the part after /some/path/ and before index.html to a $section variable, which is then used … Read more