Answer the question
In order to leave comments, you need to log in
How to configure nginx to redirect to without www on all subdomains?
There is an example.com domain that has custom subdomains *.example.com.
How to write a redirect in nginx config so that www.*.example.com addresses become *.example.com?
If from www.example.com to example.com then everything is simple.
server {
server_name www.example.com;
rewrite ^/(.*)$ example.com/$1;
}
And here with subdomains so does not work any more.
server { server_name www.*.example.com; rewrite ^/(.*)$ http://*.example.com/$1; }
server { server_name ~^(www\.)(?<domain>.+)$; return 301 $scheme://$domain$request_uri; } server { listen 80 default_server; listen [::]:80; server_name ~^(www\.)(?<domain>.+)$; }
Answer the question
In order to leave comments, you need to log in
server {
server_name ~^(www\.)(?<domain>.+)$;
return 301 $scheme://$domain$request_uri;
}
server {
listen 80 default_server;
listen [::]:80;
server_name ~^(www\.)?(?<domain>.+)$;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question