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!



  • aristath
    • Recruit

    Hello again @max,

    First of all, try adding that little piece of code in your htaccess file.

    IF there are any issues using that THEN we can proceed to handling it through the database.

    However it would be preferable to handle it from the htaccess file.

    The reason is simple and has to do with the the way servers work.

    Usually this is how it works:

    Visitor => DNS => Host => Server => Apache => PHP => MySQL

    Apache is faster than MySQL, so if we handle this using your htaccess file we will save a few precious miliseconds making your site load faster.

    I hope that helps!



  • wp.network
    • The Bug Hunter

    Thanks for your reply @aristath

    Your point about the basic stack is well taken. Precious milliseconds…

    Not knowing the bounds of my own ignorance is, at times, rather challenging :slight_smile:

    I’ve learned to try and to stay out of quagmires if I can see them.

    I take it that you don’t see any issues with @ajay‘s suggestion in terms of impact on WPMUDev plugins?

    I’ll go ahead and prioritize @ajay‘s solution then.



  • Dean
    • Design Lord, Child of Thor

    wp.network I’m basically having the exact same issue you were in this thread (Cloudflare / WPMUDev / SiteGround). I am half way there but was really wondering did you ever manage to get this working without changing the URLs in the database?

    I would assume you would need to change both the URLs in the database and add a .htaccess rule. Otherwise when WordPress creates links in menus etc it will be the non-www version and whenever someone clicks a link it would need to be redirected to the WWW version…

    Did you ever get this to work? What did you do? I would really appreciate it if you could drop a short follow up message here. Everyone I ask via the chat supports all say different things. Although the overall remark is usually just don’t use WWW on subdomains :slight_frown:.



  • wp.network
    • The Bug Hunter

    to everyone in the future: I’m happy to help if I can… however, lets do it like this: if you haven’t already, open a support ticket for your issue first, and then link to it in a reply here.

    In your ticket, please try to clearly describe:

    – what you’re trying achieve overall, briefly

    – why is using ‘www’ on subdomains significant in your use case, again briefly

    – also, please include basic server info (eg. apache, php7.?, etc.)

    – how have you tried to achieve this

    — what is working as expected

    — what is not working as expected

    — any ideas for moving forward/what does Host support say

    …if you’ll play along, then one way or another between WPMUDEV staff and community we’ll get you sorted out, probably by convincing you its not worth it to you to struggle with using ‘www’ for the network subdomains :relaxed:

    Cheers, Max

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.