Welcome! Log In Create A New Profile

Advanced

Redirecting WWW to non-WWW (HTTPS)

Posted by b.miguel12 
Redirecting WWW to non-WWW (HTTPS)
June 05, 2012 04:28AM
Hello,

I would like to ask for some help with the following Nginx configuration, so that URLs such as https://www.mywebsite.com get rewritten as https://mywebsite.com. I am currently using the following configuration:

server {
server_name www.mywebsite.com;
return 301 $scheme://mywebsite.com$request_uri;
}
server {
listen 80;
server_name mywebsite.com;

# Some more settings...
}
server {
listen 443 ssl;
server_name mywebsite.com;

ssl_certificate path_to_ssl_certificate;
ssl_certificate_key path_to_ssl_certificate_key;

# Some more settings...
}

In case that matters, the certificate I am using is a wildcard SSL certificate that was self-signed using OpenSSL on the server itself (Ubuntu 12.04). What is happening is that www.mywebsite.com correctly redirects to mywebsite.com, but https://www.mywebsite.com does not redirect to https://www.mywebsite.com (i.e., the www still appears when viewing the page in a browser). What can I be doing wrong?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 179
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready