Redirect everything except the homepage

Posted by Alex on Server Fault See other posts from Server Fault or by Alex
Published on 2010-06-18T03:36:50Z Indexed on 2010/06/18 3:43 UTC
Read the original article Hit count: 283

Filed under:
|

Is there a way in nginx to redirect everything from domain1.com to domain2.com, except for the homepage?

Right now I have:

server {
    listen 80;
    server_name www.domain1.com domain1.com;
    rewrite ^ http://domain2.com$uri permanent;
}

This works, except that I'd like http://domain1.com (without any additional path) to be left alone and not redirected. Basically, I need to redirect everything, to avoid broken links, but I want to use the homepage of domain1 to serve a static file.

© Server Fault or respective owner

Related posts about nginx

Related posts about redirect