Welcome! Log In Create A New Profile


redirect based on hostname

March 23, 2011 08:40AM
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 "www.first.com" and "www.second.com"
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: error.first.com must redirect to www.first.com as well as wrong.second.com must redirect to www.second.com

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

if ($host !~* "www.first.com") {
rewrite ^(.*)$ http://www.first.com$1 permanent;

but now my need is to do something like:

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

Thanks to anyone able to help me out with this issue...
Subject Author Posted

redirect based on hostname

sevy March 23, 2011 08:40AM

Re: redirect based on hostname

Igor Sysoev March 23, 2011 08:44AM

Re: redirect based on hostname

sevy March 23, 2011 08:47AM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 60
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready