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

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:
RewriteEngineon
RewriteCond%{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

Note: Don’t forget to replace example.com and www.exampe.com 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:
RewriteEngineon
RewriteCond%{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

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

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.

Conclusion

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:

Hostinger
$2.99 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
HostArmada
$2.49 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
Ultahost
$2.50 /mo
Starting price
Visit Ultahost
Rating based on expert review
  • User Friendly
    4.3
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.0
  • Pricing
    4.8

How to Fix Maximum Execution Time Exceeded Error Using wp-config.php

This how-to guide explains an alternative way to increase execution time limit u
less than a minute
Bruno Mirchevski
Bruno Mirchevski
Hosting Expert

How to Add a WordPress Administrator User Using PHP Code

This how-to guide explains a different way to create a WordPress administrator u
less than a minute
Bruno Mirchevski
Bruno Mirchevski
Hosting Expert

How to Add a Custom Gravatar to Your WordPress Site Using cPanel

This how-to guide provides you a solution for adding your custom Gravatar, which
less than a minute
Bruno Mirchevski
Bruno Mirchevski
Hosting Expert

How to Solve a “Warning: Error While Sending QUERY Packet” Error

This is one of the rarest errors people come across. The article will cover all
less than a minute
Bruno Mirchevski
Bruno Mirchevski
Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top