How to Force www or non-www of Your WordPress Website Using

There is a confusion between using your website URL with www or without it. But the truth is that you pick only one URL format and keep updating your website, regularly.

If you go through WordPress forums, you can notice many people asking questions related to removing www or adding www in their websites' URL.

The problem is that so-called experts have scared so many people by the term "SEO," that's why people aren't so sure whether to include www in the URL or not.

Let me clear the confusion for you. It doesn't matter whether you include www or not. Eventually, the search engine takes note on consistency and quality of your website.

If you haven't noticed, after setting up your new website, you don't see www in the URL, it's because, by default, web hosting companies pick the non-www URL, which is precise.

To maintain one format through your website, you need to force www or non-www and vice versa.

In this tutorial, you're going to learn to accomplish such a task using the .htaccess file.

I Hope You Know How to Edit the .htaccess File

If you're a newbie, you must know that .htaccess is one of the most vital files of a WordPress website, it mainly handles the redirects.

Depending on your need, you can harden your website's security using .htaccess. I remember when I started using WordPress and had no idea about such a file.

Well, if you have been using cPanel for a while, you may already know the perfect way to navigate .htaccess.

Follow these steps.

Step 1:

As always, you need to log in to your cPanel account and open the file manager from Files' section, it consists of all the core files and folders of your WordPress site.

How to Force www or non-www of Your WordPress Website Using

If you notice something unusual, it's possible that the layout of cPanel, which your web hosting company offers, maybe a little bit different.

If you use Bluehost, it's going to be blue. But overall, the options remain similar. You can easily find the file manager icon.

Step 2:

Once you see a new page, make sure, you open the root directory or public_html. It's possible that you might see the home directory, first.

Choose public_html from the left vertical navigation menu.

Step 3:

If you have only one website on your server, you can find its data on this page. Search for the .htaccess file.

How to Force www or non-www of Your WordPress Website Using

Note: It's important to check the settings from the top-right corner to see the hidden files.

As you can see, .htaccess has a dot prefix, which reflects its nature to be a hidden file. Once you find the file, right-click to edit.

As always, you can also use the traditional Edit option from the main cPanel's navigation menu.

Step 4:

A popup appears to authenticate your permission to edit. Click on Edit button, and a new tab opens up on the browser.

How to Force www or non-www of Your WordPress Website Using

Now is the place to add the code.

Make sure, you add an extra code before #End WordPress comment, but if you're not so techie, add it at the bottom of the file.

Code to force WWW.

#To Force www:
RewriteCond%{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301,NC]

Note: Don't forget to replace and with your website's domain name.

Now if you don't want to show www whenever someone opens your website, you can add another code.

Code to force non-www

#To Force non-www:
RewriteCond%{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

Just like before, you should add your domain name instead of

Click Save Changes to modify the file.

Now if you check your website, URLs display the result accordingly. Congrats, you have successfully force www or non-www to your WordPress website.

I Hope You Can Figure Out What's Best for Your Site

In most cases, people fret a lot because of their concern about maintaining a perfect SEO score. Well, it's important to notice that the URL format doesn't change anything until you keep using the same format from the starting.

If you keep switching between www and non-www, it will affect the SEO, but if you keep using one, it's perfect, that's why it's necessary to choose carefully.


Keeping SEO in your mind, you must make sure; you never remain in confusion. Forcing www or non-www is useful only when you decide to use any of two for a lifetime.

I hope you don't face such difficulty in adding the redirect code.

Check out these top 3 cPanel hosting services:

Was this article helpful?