Based in configuration, I have mentioned here: 400 Bad Request after installing LetsEncrypt SSL on WordPress Multisite installation
I created a WordPress Multisite installation with subdomains and mapped domains capability using EasyEngine commands.
Have successfully installed SSL for all the subdomains and mapped domains ( but not using easy easyengine commands like ee site create example.com --wp --lets encrypt ) but using different independent approach similar to https://easyengine.io/tutorials/nginx/letsencrypt/ )
Everything is set and working but the thing is - I want to have www in my URL. It wasn’t my choice, but I have noticed that by default easyengine creates site without www URL.
Though it’s easy to get WWW URL with WP single installation ( by modifying home url and site url in wordpress dashboard - general settings) and there are various options for multisite as well, but nothing worked for me ( I have searched the whole internet, literally )
One very exciting solution was to change Home URL and Site URL for all multisites sites as well using this tutorial: https://premium.wpmudev.org/forums/topic/how-to-change-url-for-wp-multi-site?fbc=b
It worked for the primary domain ( in my case www.presspeace.com ) but not for other subdomains and mapped domains.
It gave ‘INFINITE REDIRECT LOOP’ issue.
Other server-side method include things written here: https://easyengine.io/tutorials/nginx/www-non-www-redirection/
Well I tried it as well but it gives this weird error:
Yes, it somehow adds ‘TWO WWW’, don’t know why.
I have tried adding redirection code to ssl.conf and domain.com conf too, but same issue. Most relatable and my current configuration for related files are:
/etc/nginx/sites-enabled/presspeace.com and /etc/nginx/sites-available/presspeace.com both conf:
server {
# Uncomment the following line for domain mapping
listen 80;
server_name presspeace.com *.presspeace.com www.presspeace.com test.presspeace.com www.test.presspeace.com mappedomain.com www.mappedomain.com ;
# Uncomment the following line for domain mapping
server_name_in_redirect off;
access_log /var/log/nginx/presspeace.com.access.log rt_cache;
error_log /var/log/nginx/presspeace.com.error.log;
root /var/www/presspeace.com/htdocs;
if ( $http_host ~* "(?!www\.).") {
rewrite ^ https://www.$host$request_uri permanent;
}
index index.php index.html index.htm;
include common/wpfc.conf;
include common/wpcommon.conf;
include common/locations.conf;
include /var/www/presspeace.com/conf/nginx/*.conf;
}
Notice that I have insterted this redirection code under above shown conf file:
if ( $http_host ~* "(?!www\.).") { rewrite ^ https://www.$host$request_uri permanent; }
I have deleted a file named ‘default’ from both
/etc/nginx/sites-enabled/ and /etc/nginx/sites-available/ as instructed at some place.
My SSL.conf file looks like this under: /var/www/presspeace.com/conf/nginx
listen 443 ssl http2; ssl_certificate /etc/letsencrypt/live/presspeace.com-0002/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/presspeace.com-0002/privkey.pem; if ($scheme = http) { return 301 https://$host$request_uri; }
I also tried adding this file to presspeace.com nginx conf:
`server {
server_name “~^(?!www.).*” ;
return 301 $scheme://www.$host$request_uri;
}
`
But all these gives the ‘TWO TIMES WWW’ (ie. https://www.www.presspeace.com/ ) ERROR.
I am no developer so, whatever I do or have done is with the help of common sense and internet friends.
Kindly see if you can give any further input on this.
Thank you.