how to redirect user from www.myhostname.com to hostname.com

Jim Ohlstein jim at ohlste.in
Tue Apr 20 06:22:56 MSD 2010


On 4/19/10 10:11 PM, escavern wrote:
> how to redirect user from http://www.myhostname.com to http://hostname.com ??
> i mean if they access http://www.myhostname.com he will be redirected to http://hostname.com
> pls help me


server {
    listen 80;
    server_name hostname.com;
    ...
}

server (
    listen 80;
    server_name www.myhostname.com;
    rewrite ^  http://hostname.com$request_uri? permanent;
}

This assumes you want a redirect to the requested URI. If you want all 
requests to go to the index page for http://hostname.com omit 
"$request_uri?" from the rewrite.


>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?2,76883,76883#msg-76883
>
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx


-- 
Jim Ohlstein



More information about the nginx mailing list