How to redir php site created by WordOps from non-www to www version

http://example.com > https://www.example.com
http://www.example.com > https://www.example.com
https://example.com > https://www.example.com
http://example.com > https://www.example.com
http://example.com > https://www.example.com

You can redir php site from non-www to www version created with WordOps as following:

In `/etc/nginx/sites-available/example.com` remove non-www version from `server_name` (leave www.example.com`, remove `example.com`).

In `/etc/nginx/conf.d/force-ssl-example.com.conf` edit file like to avoid double redirect like "1. http > https, 2. https > https+www":

server {
        listen 80;
        listen [::]:80;
        server_name example.com www.example.com;
        return 301 https://www.example.com$request_uri;
}

Create new file `nano /etc/nginx/conf.d/force-ssl-example.com-redir.conf`:

server {
    server_name example.com;
    include /var/www/example.com/conf/nginx/ssl.conf;
    return 301 https://www.example.com$request_uri;
}

Restart server:

nginx -t
service nginx restart

That's it!

Log in or register to post or comment in the forum.

Add new comment