nginx folder redirect

Posted by orbalon on Server Fault See other posts from Server Fault or by orbalon
Published on 2010-03-02T20:37:31Z Indexed on 2010/03/08 13:38 UTC
Read the original article Hit count: 524

Filed under:
|
|

I'm trying redirect from an exact folder in nginx.conf

Given the URL: domain.com/path1/path2/path3

Redirect to: sub.domain.com/path1/path2/path3

Here's what I have so far:

location ~* ^/path1[\/?]$ {
    rewrite ^/(.*) http:sub.domain.com/$1 break;
}

I had it working with

location /path1 {
    rewrite ^/(.*) http:sub.domain.com/$1 break;
}

The problem with that is it also redirects a page like domain.com/path1moretext/someotherpath to sub.domain.com/path1moretext/someotherpath

Which is not what I want. (had to take out the "//" in the href code above because this is my first post, sorry).

© Server Fault or respective owner

Related posts about nginx

Related posts about pcre