Goal: Force 'www' for all subdomain sites – CloudFlare & WPMUDev Compatibility!


I hope your day is going well!

I need to force all my sites to use only ‘www’ in their addresses as a requisite to using CloudFlare (as integrated with my hosting at SiteGround.com).

I have previously posted a thread about part of this.

In that previous post, I drew on a code example from here as a possible solution.

@Ajay awesomely suggested the following instead:

RewriteCond %{HTTP_HOST} !^(www.|$) [NC]

RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

as well as some further suggestions.

@Tyler Postle seemed to think that @Ajay’s input looked viable so I ran it by my host, asking some additional CloudFlare and SiteGround specific Qs as well.

Their responses were:

In your case I think the best option is to configure each sub-domain to work via www directly from the database of the website . This way you will enforce the “www.” for the sub-domains of the WordPress multi site.

The server aliases are already set to work as intended and there is no need to make any further modifications there.

You have to include the “www.” in the blogs that you use via the database of the website. In your case the information of the WordPress multisite is contained in a single database and you have to edit the MYPREFIX_blogs table and include the “www.” in the name of the sub-domain. Additionally each sub-domain which is part of the multi site network has its own options table in this case ( MYPREFIX_2_options -> this is the options table for the sub-domain). In that table you have to include the “www.” in addition to the other modification in order for the website to work over “www.”

I think this modification will be sufficient in order for the sub-domains to work over “www”.

As for the rewrite rules you can include them in the .htaccess file of the website and see if the forced redirect will work as intended.

I think those rewrite rules may not be needed. The specified “www” in the database I think will be sufficient for the CloudFlare Service to work as intended.

(emphasis mine)

My Questions:

1) Can you help me evaluate what they are talking about having me do?

I have cpanel, and have edited tables directly before, but only with careful directions. Its not something I have had alot of practice at yet. Looks like this may be my moment.

This does seem to bring up some of my other Qs from the previous thread, namely:

2) How/If the solutions suggested by @Ajay and by SiteGround effect the use of

a) Domain Mapping (this seems like it should be fine if my approach is to make database changes only for sites without mapped addresses – Domain Mapping itself seems to take care of the whole issue for mapped domains, I’ve had no problems setting up http://www.mappeddomains.tld with CF in the past)

b) Multi-Domains (I’m not so sure about this one)

c) Multi-DB (this question just kinda scares me)

d) other WPMUDev plugins?

3) Any other suggestions?

I feel like I’ve got shards of understanding, and no duct tape…

Your help on this is so appreciated!