2

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.

3

This should do the trick.

server {
    listen 80;
    server_name www.domain1.com domain1.com;

    location = / {
            index static.file;   # CHANGE THIS
            root /path/to/root/; # CHANGE THIS
    }

    location / {
            rewrite ^ http://domain2.com$uri permanent;
    }
}
  • Thanks, but unfortunately, this didn't work for me. – Alex Jun 18 '10 at 17:14
  • My apologies, I gave it some extra thoughts and edited it, this should show static.file only for location / (nothing!) and otherwise redirect, even if the static.file is called directly. – Martin Fjordvald Jun 19 '10 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy