Redirect from WWW to Non-WWW on NGINX


#1

Hi,

I am running website on WP + wocommerce on Ubuntu 18.04 x64 with easyengine.

Using SSL with Let’encrypt.

Just want to redirect from www to non-www, Please let me know how to do.

thanks


#2

Hi, I write a rules for NGINX recirect then HSTS allow

server {
    listen 80;
    listen [::]:80;
    server_name www.exemplo.com.br;
    return 301 https://www.exemplo.com.br$request_uri;
}
server {
    listen 80;
    listen [::]:80;
    server_name exemplo.com.br;
    return 301 https://exemplo.com.br$request_uri;
}
server {
    server_name www.exemplo.com.br;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    ssl on;
    return 301 $scheme://exemplo.com.br$request_uri;
    ssl_certificate /etc/letsencrypt/live/exemplo.com.br/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/exemplo.com.br/privkey.pem;
    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
}
server {
    server_name exemplo.com.br;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    ssl on;
    ssl_certificate /etc/letsencrypt/live/exemplo.com.br/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/exemplo.com.br/privkey.pem;
    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
}

For more see my github page: nginx-hsts-redirect


#3

Actually, your WordPress should take care of this redirection.

What’s the result of:

wp option get home

#4