Allow www for multi-site main domain without redirecting

Hi - here is my situation....

I have a multi-site network running on a virtual private server at 1and1. Let's say the domain is domain.com. This is for a company that runs a windows network internally, and the windows domain is also called domain.com.

Because of that, if someone inside the company types domain.com in their browser, their Windows DNS server sends them to the internal IP address. The only way I can get the company users to be able to access the external WPMU site, is to have them type http://www.domain.com.

My question is how best can I do this? I tried to change this before, with not good results.

In the 1&1 Plesk panel, I have the preferred domain currently set to domain.com. The other options are http://www.domain.com, and "none".

I had previously tried to change it to http://www.domain.com, without changing anything else, and the site became inaccessible. This is what I think I have to do....

I think in wp-config I need to change DOMAIN_CURRENT_SITE to read

define('DOMAIN_CURRENT_SITE', 'www.domain.com');

Do I need to rename the primary domain in the WPMU admin, under Network Admin\Sites?

I think in order to do that, I need to change this line:

define('BLOG_ID_CURRENT_SITE', 1);

and change the 1 to another number, then rename site 1, then change it back to a 1.

In Plesk, I would change the preferred domain to http://www.domain.com

Is that how I accomplish what I want to do, or am I missing something?

Thanks!

  • Adam Czajczyk

    Hello Alaa,

    I hope you're well today and thank you for your question!

    The procedure that you described should work, I think but in case it didn't - it seems to be fully reversible, fortunately. I'm not sure however if it will help here indeed.

    Is your multisite installation sub-domain or sub-folder based? In case of sub-domain based install, the "www" setup is not recommended and could break entire network. Is it impossible to add some kind of redirect/exception to that internal network config so it would forward that particular domain.com and it's sub-domains to an external site? That'd be the best solution here if possible.

    Please advise!
    Best regards,
    Adam

  • Alaa

    Hi - thanks for the response. It is sub-domain based.

    Unfortuately there is no other way to do a redirect. The internal dns needs to have domain.com point to an internal IP. http://www.domain.com, and all my other sub-domains can point to external.

    Before, when I changed the Plesk preferred domain to www, it did break the whole site, and I had to restore from a backup to be able to login again, but that was before I was smart enough to know to change the DOMAIN_CURRENT_SITE parameter, so I'm not sure if that will allow me to make this work, or if I will break the site again and I will have to go through the painful process of restoring a backup again.

  • Adam Czajczyk

    Hello Alaa,

    Thank you for your response.

    I admit that complicates things a bit. In case of sub-folder install switching from "no www" to "www" domain doesn't result in any issues usually but in case of sub-domain install it may be a bit tricky.

    I've consulted one of my colleagues though and he suggested quite a nice workaround here that may do the job. Please take a look here:

    https://premium.wpmudev.org/project/domain-mapping/

    This is a plugin that lets you map additional domains to mult-site sub-sites. Let me explain this with an example :slight_smile:

    - your main site is under "domain.com"
    - one of sub-sites is "site.doman.com"

    - then with Domain Mapping plugin you can add "anotherdomain.com" to "site.domain.com"

    - therefore the "site.domain.com" is then available at both "site.domain.com" and "anotherdomain.com" addresses.

    This could be used to add "www" prefix to sub-sites. While all your sub-sites are now avalable under "no www" sub-domains, you could map "with www" sub-domains to them:

    - original domain is "site.domain.com"
    - mapped doman is "www.site.domain.com"

    I think that should solve the problem at least partially. Yet, the downside is still that Domain Mapping doesn't allow to map any additional domains to the main site. This we should address separately then.

    That said, since this is a sub-domain based Multisite, your doman DNS is configured to support wild-cards. I'm thinking that you could try following solution:

    1. In addition to wild-card configuration try adding CNAME record to the DNS settings for your main domain. That CNAME record should point "www" specifically to your main domain.

    It's possible that this alone would help here. WordPress would anyway redirect all incoming requests for your main site to "non-www" version but it's possible that your internal DNS'es would pass that through.

    2. If CNAME wouldn't be enough, the .htaccess redirect from "non-www" to "www" URL (for the main site only!) should fix that.

    Additionally, if this would cause issues (for the main site) still, the "Multi Domain" plugin may be of help as it allows you to use multiple domains for your install: by default it will show "domain.com" but adding "www.domain.com" could resolve this.

    This in idea worth checking I think and the good part is that it's still fully reversible so even in case something went wrong or didn't work after all, you would not need to restore you site just undo changes instead. I'd still recommend taking a full backup of the site though.

    Alternatively, the solution could be setting up a private proxy script under another domain. If the proxy would be available under "www" prefixed domain and set to only pass through traffic to and from your your Multsite and to and from your internal network, it should solve the issue as well.

    Best regards,
    Adam

  • Alaa

    Thank you for the detailed response! I have already installed the domain mapping plugin and have been playing with it. It seems like www is a reserved subdomain, and I can't explicitly create a www subdomain.

    I am trying to work through some other issues, but I think in the end the domain mapping will be the answer - I will just have to have internal users use a subdomain other than www to get to the external site.

    Thanks again for your excellent post!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.