To WWW or Not to WWW? How to Add WWW to Your URLs in WordPress

There are a number of reasons you might need to change the URL of your WordPress site. Say a change to the brand, or the required switch from HTTP to HTTPS for security purposes. Then, of course, there’s the matter of updating a website from www to a naked (non-www) URL.

In the following tutorial, I’ll explain why you might want to add www to your URLs in WordPress and provide you with a couple of methods for doing so.

Reasons to Use WWW

At first glance, it might not seem like there’s a whole bunch of difference between the Zapier non-www URL:

Zapier non-WWW

And the Salesforce www URL:

Salesforce WWW

Both are located on an encrypted connection (as evidenced by the https:// prefix). And they both use a clear and concise .com domain name.

However, there is a reason why one of those websites uses www and the other does not.

Larger websites that contain subdomains must use www. Ultimately, it boils down to how the visitors’ browsers handle cookies.

With www, browsers store cookies for the website as a whole, including all subdomains.

Without www, browsers have to store a different cookie for every subdomain request. As you can imagine, the process is highly inefficient and slows down loading times on the website as a result.

Aside from that one (very good) reason, the difference between www and non-www is superficial.

How to Add WWW in WordPress

For those who would like to add www to your WordPress website–regardless of whether it’s for a site with multiple subdomains–there are a couple of ways to do this.

Just be careful. One wrong move and you could end up with the white screen of death. It might be simple to execute the change from non-www to www, but it will have far-reaching effects on your website. It will change:

  • The web address on the frontend for visitors.
  • The login URL for you and other WordPress users’ backend access.
  • The functioning of internal and external links pointing to the website.

Before adding www in WordPress, read the following instructions thoroughly.

1. Add WWW in the WordPress Admin

From the WordPress dashboard, visit General Settings. On this screen, you’ll need to update these two fields:

General Settings Update

Add www. after “https://” and hit Save Changes.

WordPress should instantly log you out at this time. If it doesn’t, you’ll want to do this on your own.

To log back in, enter your admin URL into the browser window. This time, however, add www. to it.

If you can’t log in after doing this, you need to refresh the server cache. If you continue to experience issues, use the next option.

2. Add WWW with the wp-config.php File

If you want to hard-code the domain name change into the website, use the wp-config.php file to do so.

Visit your control panel and open your file manager or FTP manager. Then, locate the wp-config.php file and add the following lines of code:

define( 'WP_HOME', 'https://www.better-businesses-etc.com' );
define( 'WP_SITEURL', 'https://www.better-businesses-etc' );

Just remember to replace better-businesses-etc.com with your domain name. When you’re done, save your changes.

One quick thing to note:

The wp-config.php settings will always override the domain name settings in the WordPress dashboard. If you experienced issues trying to add www in WordPress and clearing the cache didn’t work, it’s probably because someone already hard-coded the non-www URL into this file. Do a search for the lines above and edit them to reflect the domain name structure you need them to be.

3. Perform a Database Search and Replace

Depending on your plugins and theme, you might need to also perform a search and replace on the database to change all other references of the old non-WWW URL to the new one. The easiest way to do this is through WP-CLI.

More information on doing this can be found on our Performing a Search and Replace with WP-CLI documentation.

Why You Should Implement a 301 Redirect

If you’re wondering, “Why don’t I just create a version of my website at www and one at non-www? Wouldn’t that be easier?”

Here’s the thing:

It’s not ideal to have both a www and non-www version of a website in existence. There are a couple of reasons for this.

To start, Google indexes website content and associates it with the full URL. If you launched your WordPress site with a non-www domain and then decide a year down the line you want to change it, Google will have to index the www version of it from scratch and you’ll lose all that good link juice you accumulated.

Creating a www mirror image of the non-www website would pose problems in SEO as well. Google bots don’t understand that you’re doing this for the purposes of capturing any and all traffic that goes to the www or the non-www of your website. Google bots will see this and try to rank both versions of the site simultaneously. So, not only will your content compete against itself, but it’ll suffer a penalty for listing duplicate content in search.

Bottom line: you should choose whether to add www to your WordPress site or just leave it out altogether. But make a choice and stick to it.

Then, when you’ve committed to your URL, set up a 301 redirect.

Go to your domain manager and configure a 301 redirect to push traffic from the non-www:

https://better-businesses-etc.localhost

To the www URL:

https://www.better-businesses-etc.localhost

This ensures you capture all web traffic looking for your brand who might stumble on the wrong or older version of your URL.

Final Thoughts

To www or not to www? That was the question here today.

As you have learned, there are clear reasons why large websites with subdomains should use www. For everyone else, the choice is yours to make. If you like how it looks, or you want to be 100% sure that people who know your brand name can find you, go ahead and add www to your WordPress site. Just make sure you follow the steps above to ensure it’s properly implemented.

New Posts in your inbox

  1. Hi Shaun,

    I’ve been trying to do exactly this, but for some reason I can’t get my site to load.

    I’ve been trying to adjust my WP settings to make the URL begin with http:// www instead of http://

    I have also attempted a more thorough database rewrite where I replace every mention of the http:// url with http:// www, but under no circumstances can I get the site to load at the end. If I reverse all the changes, I can get back on the plain http:// url.

    Any ideas what’s going wrong here?

  2. Not sure how to interpret what you write. Are you saying that wordpress AUTOMATICALLY does the redirect non-WWW to WWW (and vice versa) and that the change in settings is for those who want to make a change overall? I have a WordPress site that works without WWW but does not work with it. You seem to imply that the redirect is a built-in WordPress feature that works regardless of what is specified in settings > general.

  3. Unfortunately, it’s not always that straightforward. If you have certain settings in your .htaccess, then simply changing via the wordpress dashboard can cause issues.

  4. My new site doesn’t have www in the Site URL and WordPress URL settings. But when I try to type www.domain.com, I get a message that there were too many redirects. Typing just domain.com without the www. works fine. Why doesn’t the automatic redirect work? I’m not aware of any other redirects going on.

  5. hey bro, I change WordPress address URL(your first point) from http:// to https:// and now it showing me 404I don’t have access to my website. now, what should I do?

  6. My new site doesn’t have www in the Site URL and WordPress URL settings. But when I try to type http://www.domain.com, I get a message that there were too many redirects. Typing just domain.com without the www. works fine. Why doesn’t the automatic redirect work? I’m not aware of any other redirects going on.

  7. An extremely important aspect that everyone forgets and I realized it only when I encountered in today is that we also need to check the DNS records for the CNAME value of www.

    We were struggling with different WordPress installations for a client only to realize that the CNAME record for www -> @ was not present in the DNS records set.

    Abhishek P (adhoonik.com)