Yet another nginx rewrite rule question:
How can I do a rewrite from http://www.*.domain.com to http://*.domain.com?
if ($host ~* www\.(.*)) {
  set $host_without_www $1;
  rewrite ^(.*)$ http://$host_without_www$1 permanent; # $1 contains '/foo', not 'www.mydomain.com/foo'
}
Answer from server fault: https://serverfault.com/questions/139579/nginx-subdomain-rewrite
server {
  listen 80;
  listen 443;
  server_name ~^www\.(\w+)\.domain\.com$;
  location / {
    rewrite ^ $scheme://$1.domain.com$request_uri? permanent;
  }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With