Rewrite rule for all domains.

Jonathan Matthews contact at jpluscplusm.com
Tue Apr 16 15:07:26 UTC 2013


On 16 April 2013 15:47, David | StyleFlare <david at styleflare.com> wrote:
> Pardon me if I missed this in the docs...
>
> My issue is that I want to rewrite every domain and not create a server
> block for each.
>
> I am trying to rewrite every domain thats pointing to Nginx
>
> from www.server.com to server.com

Have a single separate server block do it for you:

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

(written but not tested; YMMV!)

Jonathan



More information about the nginx mailing list