nginx redirect to a subdomain even without trailing slashes

Posted by Oliver A. on Server Fault See other posts from Server Fault or by Oliver A.
Published on 2011-03-10T23:24:51Z Indexed on 2011/03/11 0:11 UTC
Read the original article Hit count: 470

Filed under:
|
|
|

Hi,

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 www.mydomain.com/forum/ AND www.mydomain.com/forum (note the missing trailing slash; case-insensitive; same applies for "forums" instead of "forum") to forum.mydomain.com/. This is what I came up with:

location ~* ^/(forum|forums) {
rewrite ^/(.*)/(.*)$ http://forum.mydomain.com/$2? permanent;
}

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

Please help me! Thanks in advance!

© Server Fault or respective owner

Related posts about webserver

Related posts about nginx