Re:Nginx 1.6.0 stable released
by richardjs on Thursday April 24, 2014 @12:22PM
(#7641232)
Your specs look a lot like ours (we have a CMS that adds a trailing /index to every page that is part of the core navigation, and we don't want that). Here's the three primary rewrite rules we use for the issue; they don't match your spec exactly, but they might help you get started:
Edit: There's a couple extra directives that go along with the above to make it work that I neglected to include:
Also, for error pages, you can probably just use the error_page directive:
[ Parent
| on HN ]
Re:Nginx 1.6.0 stable released
by jcampbell1 on Thursday April 24, 2014 @01:23PM
(#7641611)
I have had problems using rewrite in this way. The URL that rewrite analyses may have already been changed by `index` or some other command, and this will lead to redirect loops. To avoid that problem, I have used:
if ($request_uri ~* "^(.*)\.html?$") {
return 301 $1;
}
The above is a safe use of "if", and can be helpful since it operates on the actual uri, not the internal uri.