how to redirect www to non www

How to Redirect www to non-www on WordPress?

Are you confused about whether or not to prefix www next to your website URL? Don’t worry. You aren’t the only one facing this common dilemma! If WordPress forums and Facebook groups are anything to go by, there are hoards of WordPressers who are wondering which is the better choice — adding or removing www in their website URL. No matter what side you’re on, your confusion shouldn’t lead you to have both domain versions running simultaneously. Also, there should be consistency across your entire website settings. 

The confusion (mostly among newbie developers) is less about the haziness around which version (with www or without) is more aesthetically appealing but whether there could be SEO related repercussions. 

The truth of the matter is including www or not, isn’t important. The important thing is to ensure the consistency and quality of your website. Search engines pay heed to consistent websites, and being in the search engine’s good books means better SEO.

Having said the above, running your website on www or non-www URLs may be for aesthetic and personal preference, yet you should stick to one to keep your choice consistent to prevent redundant hostnames. If you don’t want Google Analytics to give you a “Redundant Hostnames” warning, it’s advisable to maintain your website’s hostname the same throughout — whether with the www part or without the www part.

To stick to one format throughout your website, you’ll have to force www or non-www and vice versa. You can’t have both versions across the website settings.

In this guide, you’ll learn how to redirect www to non-www on WordPress using the .htaccess file. Alternatively, we’ll show you how to do a permanent HTTP 301 redirect via your cPanel account for accomplishing this. 

How To Redirect WWW To Non-WWW?

For redirecting www to non-www and vice versa, we’ll be outlining 2 easy methods, One of which is using .htaccess (through cPanel), and the other is by using cPanel directly. Let’s begin with the .htaccess method first.

1. Redirect www. To non-www on WordPress using .htaccess

It is the .htaccess file that primarily handles the redirects of your WordPress website. Moreover, the .htaccess file is the right place to tighten your website security further. To access this file, your best option is to navigate to it through cPanel. 

# Here are the steps:

Step 1 – Log into your cPanel and open the file manager from the Files section to gain access to your site’s core files and folders.

Redirect www. To non-www on WordPress

Step 2 – If you see the home directory appear, open the root directory or public_html by selecting public_html from the navigation menu aligned vertically to the left of your screen.

How to Redirect www to non www WordPress

Step 3 – Search for the .htaccess file and right-click on it to ‘Edit.’ Alternatively, you can use the Edit button on the cPanel menu. 

Step 4 – A popup will appear; here, click on the ‘Edit’ button. 

Redirect www to non www WordPress

Step 5 – Now, a new tab will open, where you can add the code. Therefore, in this, your main, root .htaccess file, add the lines of code given below. Make sure to change salvattore.com to your hostname.

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.salvattore\.com [NC]

RewriteRule ^(.*)$ http://salvattore.com/$1 [L,R=301]

</IfModule>

Step 6 – ‘Save’ Changes to modify this file.

Congrats, you’re done! You have successfully redirected www to non-www on your WordPress website.

Note: To redirect non-www to www, use the following code in step 5 above:

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{HTTP_HOST} ^salvattore\.com [NC]

RewriteRule ^(.*)$ http://www.salvattore.com/$1 [L,R=301]

</IfModule>

In the above code, make sure to change salvattore.com to your hostname. 

‘Save’ Changes to modify this file.

Congrats, you’re done! You have successfully redirected non-www to www on your WordPress website.

2. Redirect www. To non-www on WordPress using cPanel

This is another quick and easy method. Begin by logging into your cPanel. Once you’re on the main cPanel page, go to Domains > Redirects.

Next, follow the instructions labeled A through F as below:

Redirect www. To non-www on WordPress using cPanel

A. Set it to permanent type to give it a 301 HTTP status code.

B. Select your domain name from the http://www. drop-down menu.

C. This path is to be left empty since our target is to redirect the whole domain.

D. In the “Redirects to” section, write your URL without the “www” prefix because that’s the way you want to set it.

E. Make the selection: “Only redirect with www. “This ensures redirection is from www to non-www.

F. “Wild Card Redirect” is to be left unchecked.

Once done, click on the ‘Add’ button, and you’re done!

Why Implement a 301 Redirect Status code?

Setting up a 301 redirect ensures you benefit by maximizing web traffic looking for your brand. This is because by setting up a 301 redirect, you’ve eliminated the chance of visitors ending up on the wrong or previous versions of your website URL.

Here’s why you shouldn’t have both www and non-www versions of your WordPress website running:

  • Google’s indexing of a website’s content is associated with the full URL of the website. If you start with a www domain name and running it that way you decide to change it to a non-www domain, you lose the previous Google indexing status. 
  • By running both versions, the SEO “browny points” end up being shared. If you have both www and non-www versions of your website running, your content ends up competing against each other. Google bots will notice this and rank both versions of your website at the same time. Further, in the search results, your content is found in duplicate, whereby it suffers a penalty in terms of lacking good SEO.

Final Thoughts

To avoid the above problems and capture the entire web traffic looking for your brand, you must stick with either www or non-www so that you’re committed to your URL for a lifetime. In this guide, we’ve shown you two easy methods of redirecting www to non-www on WordPress. Further, to permanently validate your choice, we’ve stressed the importance of setting up a 301 redirect.

If you have additional tips or methods to share about solving this issue, comment below.

If you enjoyed reading this guide, you might also gain from reading our guide on: 

How To Create A Custom Taxonomy In WordPress?

4 Ways to Perform WordPress Database Cleanup

How to Update PHP Version of Your WordPress Website

Leave a Comment

Your email address will not be published. Required fields are marked *