Regular Expression global redirect

Edho Arief edho at myconan.net
Sun Feb 26 06:10:00 UTC 2012


On 2012-02-26 10:59, altiamge wrote:
> I'm using nginx as a reverse proxy for about 2000 websites. I'm trying
> to find a good way to redirect all www traffic to nonwww addresses. I
> don't want to have a separate entry for every domain...just a global
> redirect in the server block preferably. I found lots of examples to do
> this one domain at a time, but does anyone have any suggestions on how
> to do it for the whole server?
>

This is what I'm using:

server {
   listen 80;
   server_name ~^www\.(?<domain>.+)$;
   rewrite ^ $scheme://$domain$request_uri? permanent;
}



More information about the nginx mailing list