Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just installed and partially configured nginx on a dedicated server of mine. But I've got some trouble understanding the regexp. I would like to make nginx redirect AND (note the missing trailing slash; case-insensitive; same applies for "forums" instead of "forum") to This is what I came up with:

location ~* ^/(forum|forums) {
rewrite ^/(.*)/(.*)$$2? permanent;

... but for some reason it works with trailing slashes only. :-/

Please help me! Thanks in advance!

share|improve this question
up vote 1 down vote accepted


location ~* ^/(forum|forums)/? {
   rewrite ^/(.*)/(.*)$$2? permanent;


Ok the location seems to be working, the problem is probably the rewrite line.

location ~* ^/forums?/?$ {
   rewrite /forums?/?(.*)$1 permanent;

Tested the regex on pcretest and it captured it right, see if it works.

share|improve this answer
Thanks for your reply. However this didn't fix the problem :-( – Oliver A. Mar 10 '11 at 23:37
Can you provide example URLS (original and how it should end) – coredump Mar 10 '11 at 23:42
See my initial post: hxxp:// (please note the missing trailing slash) -> hxxp://, but still hxxp:// -> hxxp:// (replace xx with tt, trying to bypass's limitations here :-P) – Oliver A. Mar 10 '11 at 23:45
Thanks a lot!!! location ~* ^/(forum|forums)?/?$ { rewrite /(.*)?/?(.*)$2 permanent; } works like a charm! – Oliver A. Mar 11 '11 at 0:02
@oliver wait, what? :P – coredump Mar 11 '11 at 0:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.