Categories: cPanel

How to force www or non-www in your .htaccess file in cPanel

How to force www or non-www in your .htaccess file in cPanel

Many customers at some point request to force either the www or non-www version of their site to display in their visitor’s browser. Though this results in the same site being displayed there is some thought that using only one version is better for search engine optimization. This article will guide you through how to force your site to use either version by making a change in the .htaccess file.

Force www or non-www in your .htaccess file in cPanel

Step 1:  Log into your cPanel.

Step 2: Find the Files category and click on the File Manager icon.
  

 

 

Step 3 : A popup box will appear. For the primary domain, click on the Web Root radio button. For addon domains, click on the dropdown and find your desired addon domain name. Be sure the checkbox next to Show Hidden Files is checked.

Step 4 : Click the Go button to enter the File Manager.

Step 5 : You should now be in the root folder of the domain you chose. Look for the .htaccess file and right click on it. This brings up a menu.

Step 6 : Find and click on the Edit option. If you get a popup box, simply find and click the Edit button in the lower right corner to continue to the editor.

 Step 7 : You are now in the text editor. Place either selection of code in the file and click on the Save Changes button at the top right corner of the screen. Be sure to replace ‘example.com‘ with your actual domain name.

NOTE: Do not place both selections of code in the file as it will cause an error.

    #Force www:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

    #Force non-www:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
    RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

 Step 8 : Once you insert the code, click on the Save Changes button in the upper right corner to save the code change. You can now type your domain name either with or without the www and it will display in the address bar in the format you have set the code for.

 


Vishwajit Kale
Vishwajit Kale blazed onto the digital marketing scene back in 2015 and is the digital marketing strategist of Hostripples, a company that aims to provide affordable web hosting solutions. Vishwajit is experienced in digital and content marketing along with SEO. He's fond of writing technology blogs, traveling and reading.

Recent Posts

The Ultimate Guide to WordPress Maintenance: Tips and Tricks

When you’re running a business that relies on website traffic and sales to succeed. Then you need to keep it…

1 week ago

Migrate In 2024: Our Comprehensive Website Migration Manual to the Next Level

Migration! Yes, this word is very big in the web hosting industry and it has its importance. Especially for businesses…

1 week ago

Unveiling the Importance of Server Maintenance Plans: A Comprehensive Guide

The server is the backbone of the web hosting industry and it acts like a HERO in the web hosting…

2 weeks ago

IP Address is Blocked? A handpicked list of Solutions to Fix it?

Imagine you are on holiday having a cup of tea and browsing your website or blog.Then, what next?You will get…

4 weeks ago

Explained: Difference between Nameservers Vs. DNS

The web hosting industry is growing every minute, day, and year. It has many terminologies that are important to understand…

1 month ago