0

I want to remove www. from both the main site and all sublevel domains. I don't care how many levels into the TLD I am; www is banned from use. It should issue a 301 redirect.

  • www.example.com
  • www.123.example.com

I wrote the following server block, but it doesn't seem to work.

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

2 Answers 2

0

Here is how I would do this:

server {
   listen       80;
   server_name  ~^www\.(?<domain>.+?)$;
   return 301 $scheme://$domain/$request_uri;
}
4
  • um, that is what I'm doing minus the capture group.
    – Xeoncross
    Jul 14, 2014 at 21:40
  • Have you tried it? Jul 14, 2014 at 21:48
  • yes sir, it is the same though. Just one more loose $1 floating around...
    – Xeoncross
    Jul 14, 2014 at 21:49
  • So, what doesn't work exactly? Jul 14, 2014 at 21:59
0

From this question:

if ($http_host ~* "^www\.(.+)$"){
rewrite ^(.*)$ http://%1$request_uri redirect;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .