Force non-www version for all sites on your account

When working with redirects in your htaccess, you are able to do specific things such as force a www or non-www version of your site. But since the .htaccess file is recursive, why not have some code that you can create once and have it work for all the sites on your account? This article demonstrates how you can force the non-www version of all sites on your account with a single piece of code.

Don’t have time to read our full article? Watch our walk-through video.

Force non-www on all sites on your account

  1. Log into your cPanel dashboard.
  2. Click on the File Manager icon located in the Files category, selecting the Web Root as the location.
  3. From the web root (public_html folder) open the .htaccess file for editing. If one does not exist, create a new one, then open the blank file for editing.
  4. Once the file is open, paste the following code at the top of the file:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]
  5. Save the changes to the file.

Now you can test the code by visiting the www version of your site. It should redirect in the address bar to the non-www version.

2 thoughts on “Force non-www version for all sites on your account

Was this article helpful? Join the conversation!

Leap into Savings
Leap Ahead with Limited Time Deals