What I want to do
I want to redirect all to https non-www
http://mytestwebsite.com > https://mytestwebsite.com
http://www.mytestwebsite.com > https://mytestwebsite.com
https://www.mytestwebsite.com > https://mytestwebsite.com
I tried this
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name www.mytestwebsite.com mytestwebsite.com;
return 301 https://mytestwebsite.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
if ($host = www.mytestwebsite.com) {
return 301 https://mytestwebsite.com$request_uri;
}
server_name www.mytestwebsite.com mytestwebsite.com;
ssl_certificate /home/mysite/ssl.cert;
ssl_certificate_key /home/mysite/ssl.key;
# SSL configuration
# Other configurations
}
server {
server_name "~^www\.(.*)$" ;
return 301 $scheme://$1$request_uri ;
}
With this, all works fine, except
https://www.mytestwebsite.com > https://mytestwebsite.com
I always get https://www.mytestwebsite.com
......
I tried many solutions from stackoverflow, google etc.. and nothing works. https always have www...
How to remove www from https links?