fbpx

How To Force www with .htaccess in cPanel

In this tutorial, I will show you how to force www with .htaccess in cPanel.

Including “www” in your website’s URL can really help the SEO and user experience of your website. With the cPanel, you can manage your website, and easily enforce this with the .htaccess.

What is .htaccess?

.htaccess (hypertext access) is a file in the File Manager that you can use in performing server-side configuration like URL redirection, access control, etc.

Let’s get started on how to force www with .htaccess in cPanel.

How To Force www with .htaccess in cPanel

  • Log into your cPanel. You can use your HarmonWeb client area to access your cPanel.
force www with .htaccess
  • Go to the Files section and select the File Manager.
force www with .htaccess
  • In the File Manager, navigate and open the public_html directory. This is the root directory for all your website files.
force www with .htaccess
  • If you don’t see the .htaccess file in the public_html directory, you have to enable your File Manager to show all hidden files. To enable this, click on Settings at the top right corner of the screen and check the box for Show Hidden Files (dotfiles).
force www with .htaccess
  • Right click on the .htaccess file and select Edit.
  • At the top of the .htaccess file, enter the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
  • Click on the Save changes button and close the editor. Now when you open a browser and enter your website URL without www (e.g http://example.com), it will redirect you to http://www.example.com.

Following the steps above in your cPanel, you can easily redirect your website traffic to the www version of your site.

Leave a Reply