redirect based on hostname

sevy nginx-forum at
Wed Mar 23 15:40:36 MSK 2011

I've read the whole NginX wiki and couldn't find a solution yet. So
would you be so gentle to tell me how to do this.

I have two (2) domains on the same website. Let's say ""
and ""
The frontend php shares the same files and the only difference is in the
layout so I must differentiate the layout based on the hostname header
sent by client.

My goal would be to redirect to the www domain if an invalid subdomain
is typed.

example: must redirect to as well as must redirect to

My setup when I was using a single domain was easy:

        if ($host !~* "") {
            rewrite ^(.*)$$1 permanent;

but now my need is to do something like:

        if ($host !~* "|") {
            rewrite ^(.*)$ (what to put here???)$1 permanent;

Thanks to anyone able to help me out with this issue...

Posted at Nginx Forum:,185113,185113#msg-185113

More information about the nginx mailing list