Non-www to www redirect on Multisite created using EasyEngine

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 --wp --lets encrypt ) but using different independent approach similar to )

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 :slight_smile: )
One very exciting solution was to change Home URL and Site URL for all multisites sites as well using this tutorial:
It worked for the primary domain ( in my case ) but not for other subdomains and mapped domains.


Other server-side method include things written here:
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 conf too, but same issue. Most relatable and my current configuration for related files are:

/etc/nginx/sites-enabled/ and /etc/nginx/sites-available/ both conf:

server {

# Uncomment the following line for domain mapping
listen 80;

server_name * ;

# Uncomment the following line for domain mapping
server_name_in_redirect off;

access_log /var/log/nginx/ rt_cache; 
error_log /var/log/nginx/;

root /var/www/;

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/*.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/

listen 443 ssl http2; ssl_certificate /etc/letsencrypt/live/; ssl_certificate_key /etc/letsencrypt/live/; if ($scheme = http) { return 301 https://$host$request_uri; }

I also tried adding this file to nginx conf:

`server {
server_name “~^(?!www.).*” ;
return 301 $scheme://www.$host$request_uri;

But all these gives the ‘TWO TIMES WWW’ (ie. ) 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.

Seems like $host$request_uri is returning instead of that you want (since you already have included www in your rules).

The easient option would be to simply remove the static www from your rule I assume, however, in your case, I would investigate the possible reasons for the www-added returned $host$request_uri.

Hey @ggloveswp, Thanks for the reply, I just tried what you said and removed www from there, but it starts giving this error "This page isn’t working redirected you too many times. Try clearing your cookies. ERR_TOO_MANY_REDIRECTS"


Can you paste your error.log’s latest lines here @nanowhiz ?


error.log (22.7 KB)

( error log copied from /var/log/nginx)

Sure. Just attached here. But I don’t see any correlation between the error code and files here. Also, the time is not matching with the actual time. How can I sync the time?

Also, when I try adding code to the top of /etc/nginx/sites-enabled/ like this:
server {
server_name “~^(?!www.).*” ;
return 301 $scheme://$host$request_uri;

Here, I have removed www, but this time, nothing happened. Site opened but as usual, I mean without www and without any errors.

I also noticed that when I try to open any created subdomain like it redirects to while when I open the mapped domain ( say mapped to ), it opens ( and doesn’t redirect to the ) Just telling you to guess the error. (9.4 KB)

One more error log named’ from the same folder

You can reconfigure date using dpkg-reconfigure tzdata command.

Please try the following:

Step 1: Remove every custom part of the code from /etc/nginx/sites-available/

Replace this part of the code:

server {

# Uncomment the following line for domain mapping
listen 80;

server_name * ;

# Uncomment the following line for domain mapping
server_name_in_redirect off;

with this one:

server {
listen 80;

and remove completely this part of the code:

if ( $http_host ~* "(?!www\.).") {
             rewrite ^ https://www.$host$request_uri permanent;

Do not worry for sites-enabled directory. This is just a dynamic symlink to sites-available folder.

Step 2: Remove every custom part of the code from /var/www/

Remove this part of the code (nothing more-nothing less):

if ($scheme = http) {
return 301 https://$host$request_uri;

Step 3: Reload or restart your stack.

After this step, you should be able to access wp-admin with no HTTP errors. Okay - Lets fix the www issue now.

Step 4: Access wp-admin and go to Settings -> General. Make sure that you update your URLs from (or http, if exists) to

Alternative to step 4: Use this software and replace every http:// instance to https://, then every to Make sure that you choose live run.

You should be able to access your website just fine by clicking here: and by clicking here, it sould redirect to the www URL:

  • If non-www is not redirecting to the www automatically, you need to edit /etc/nginx/sites-available/ again.

Edit it and replace this part of the code:


with this one:


and then, go to the end of the file (after closing } ) and paste the following code:

server {
    listen 80;
    return 301$request_uri;

Reloading your nginx config after the last step, (either by service nginx reload, or by reloading stack) should help you solve this issue forever :slight_smile:

Hi @ggloveswp, First of all, thank you so much for taking time to understand my issue and trying to resolve it.

Worked like charm. Thank you :slight_smile:

For the bigger part of solution that you have provided above. It appears that you misunderstood two things:

  1. I am wordpress multisite with subdomains and having server_name as * is necessary to be able to create new subsites with subdomains.
  2. I am looking for a solution to be able to redirect all kinds of URL ( non-https, https, non-www, www) to ( here domain can be, subdomain or mapped domain)

As mentioned here- 400 Bad Request after installing LetsEncrypt SSL on WordPress Multisite installation , I have already successully installed everything on multisite as well, but while trying to redirect all urls to its WWW version, I started getting this TWO WWW errors .

Though I tried to do what you have said above again and it successfully let me open , but other subdomains and mapped domain doesn’t work with this.

I am sorry if I was not clear enough with my post that it’s multisite setup ( though I have mentioned it in the Post title), but do give it a re-look in a multisite perspective, if possible.

Thanks and regards, Nitesh

Btw - I assume DNS settings are correct? I’ll dig in to this later on today.

DNS Settings: You need to create a “A” record with an asterix (*)in your DNS records, plus you “need” to give an A instead of CNAME for your www.

He needs a multidomain, so it should be *

Hey @hakabe, thanks for coming in.[quote=“hakabe, post:9, topic:8799”]
I assume DNS settings are correct? I’ll dig in to this later on today.

Yes, I use Cloudflare for my DNS management.

My primary domain is pointed correctly to the server IP with A records for both www and non-www versions of wildcards, domain and subdomains as well.

Other mapped domains have also been pointed correctly with A-records to the www and non-www versions both. [quote=“hakabe, post:9, topic:8799”]
DNS Settings: You need to create a “A” record with an asterix (*)in your DNS records, plus you “need” to give an A instead of CNAME for your www.

Yes, It’s always A on my side. Have tried with CNAME for mapped domains as well, but results remain same.

I will wait for your further response on this.


Actually all the A records are worthless when using a wildcard - at least I think so (no expert on these). I’m having a hard time following the configs and which works and which doesn’t, so can you upload them somewhere separately? layout is not the clearest one either.

Wildcard DNS entries must be of type CNAME, otherwise they won’t work as expected.

Actually, it is advised to use separate A-records in case you want working Let’s Encrypt SSL for the mapped domain and also needed if you want to use Cloudflare Proxy to work on these mapped domains. Cloudflare doesn’t support CDN for wildcard entries.

There are two working config,

  1. This is file under /etc/nginx/sites-available . In this case, I don’t need any other ssl.conf or force-ssl.conf file.

  1. This configuration needed a conf file under etc/nginx/sites-available and ssl.conf under /var/www/ file here:

ssl.conf here:

Both config is working for all mapped domains but it always open non-www version ( ie. ) Few issues that I am facing with this config.

Sudomains redirects to the primary domain but the mapped domain to these sub-domains work correctly. Unable to open the network admin page ( or say unable to install new plugins) as the network link: redirects to the home page. ir.

And the main moto of this discussion - non-www page doesn’t redirect to www-page.

Give it a look if possible.[quote=“portofacil, post:13, topic:8799, full:true”] Wildcard DNS entries must be of type CNAME, otherwise they won’t work as expected. [/quote]

Well, as per various tutorials, it shouldn’t impact and A-records are more preferable way to do wildcard entries ( since few providers like Godaddy doesn’t support CNAME wildcard entries) but I still tried it and changed wildcard entries from A-records to CNAME on Cloudflare. It’s working but couldn’t bring any positive or negative change to what I was getting before.

Thank you.

I’ll investigate. In the meanwhile, have your read this : ?

Not particularly this write-up. Let me go through it. Thank you.

Though, Please do a proper investigation whenever you have little extra time. I will keep you all updated here if I found any solution.

Thank you.

Oh, yeap, i missed your previous post since i was taking a look at the original post.

Well, in your case, I would modify let the server_name directive as it is now and I would focus on the database changes (via Search-Replace software found here ), after removing custom rewrites of:

if ( $http_host ~* "(?!www\.).") {
             rewrite ^ https://www.$host$request_uri permanent;


if ($scheme = http) {
return 301 https://$host$request_uri;

Hey @ggloveswp,
Thistime, I deleted the old site. Reinstall wordpress multisite and configure it as you have mentioned.

All is okay but mainly two issues, now it doesn’t force SSL and hence redirects to non-https version of the page.

I ran search and replace plugin for primary domain to check but after doing this, I was unable to access wordpress dashboard.

It gives, 403 Forbidden error like this:

The current cofigurations for your quick info:

/etc/nginx/sites-available/ :
/var/www/ :

Your further investigation needed :slight_smile:

Thank you.

Sounds like you replaced something in a wrong way. What does errorlog says? Is restoring a previous db backup an option? You should replaced only http:// to https://

Yes, I did exactly the same. Search and replace with

This time I had installed with ‘www’ in the domain name:

sudo ee site create --wpsubdom --wpfc

One thing to notice is that I see proper URL ie. ( ) after search and replace. I don’t what is causing this 403 error.

No I don’t have any backup. This is totally an experimental installation, and hence I have nothing to worry. I will change https:// to https by accessing PHPMyAdmin and will let you know.