redirect from www to sub-page

Igor Sysoev is at rambler-co.ru
Thu Jan 22 14:18:39 MSK 2009


On Thu, Jan 22, 2009 at 12:15:35PM +0100, ha we wrote:

> How can I redirect from www.example.com to www.example.com/new_location,
> but do not redirect if there is already a full address such as
> www.example.com/location?
> 
> I tried this
> 
>    if ($host ~* "^www.example.com$"){
>       rewrite ^(.*)$ http://www.example.com/new_location break;
>    }
> 
> But of courese it creates an infinite loop.

Never use 
    if ($host ~* "^www.example.com$"){

This means that you are on wrong way.
You should use

    server {
        server_name  www.example.com;

        location = / {
             rewrite ^   http://www.example.com/new_location;
        }
      
        location / {
             ...
        }
    }


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





More information about the nginx mailing list