Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'd like to redirect www.mydomain.com to www.mydomain2.com/try.html. These domains are on two different servers.

This is what I've tried but it does not work:

if ($http_referer ~* (www.mydomain.com) ) {
return 301 http://www.mydomain2.com/try.html;


if ($http_referer ~* (www.mydomain.com) ) {
rewrite ^ http://mydomain2.com/try.html permanent;

These two ways are not working, when I go to mydomain.com I stay on mydomain.com but... without the CSS... And I am not redirected to mydomain2.com/try.html

Any help appreciated.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Add new server section to your nginx config file

server {
    listen          80;
    server_name     mydomain.com www.mydomain.com;
    rewrite         ^ http://www.mydomain2.com/try.html permanent;

and all visitors of mydomain.com will be redirected to second site immediately.

share|improve this answer
It works!! Thanks mate! –  Emmanuel Jan 16 '13 at 8:39

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.