Redirect without changing base server name??

Igor Sysoev is at rambler-co.ru
Wed May 14 22:35:28 MSD 2008


On Wed, May 14, 2008 at 04:36:43PM +0100, Ed W wrote:

> Hi, I have a site which hosts several domains and they are all 
> redirected to a single vhost.  I then want to redirect "/" to some 
> starting URL, but when I do so the hostname in the URL changes to the 
> first server name in my config, rather than staying the same as the user 
> requested
> 
> eg, user goes to "http://webmail.theirsite.com/" and it should redirect 
> to "http://webmail.theirsite.com/src/login.php", but what actually 
> happens is that it goes to http://webmail.genericsite.com/src/login.php
> 
> Config:
> 
>        server {
>          server_name webmail.genericsite.com webmail.theirsite.com
>          rewrite ^/$ /src/login.php redirect;
>          etc
>       }
> 
> Suggestions please on how to fix this?  (Use an IF perhaps?  Seems ugly?)

What nginx version do you use ? If 0.6.x, then you should use

      server {
           server_name_in_redirect  off;

BTW, it's better to use:

          location = / {
               rewrite ^ /src/login.php redirect;
          }

instead of

          rewrite ^/$ /src/login.php redirect;

on server level.


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list