How to redirect Non-WWW to WWW with htaccess

How to redirect Non-WWW to WWW with htaccess

Having a single version of your website is good for search engine optimization. If you do not choose one from non-www and www version of you website then there are chances that search engines will look both versions as separate websites. It is not good for SEO. If you want to redirect non-www version of your website like to then you will need to insert a piece of code into your .htaccess file in your public_html directory.

Redirect Non-WWW to WWW with .htaccess

1. Login to cPanel and go to File Manager
2. In public_html directory, edit the .htaccess file
3. Insert this code into it:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

4. Make sure to change to your own domain name and save the file.
5. Now whenever you type your domain as it will automatically redirect to every time.

Note: .htaccess file is a dot file (starting with dot) so it is normally hidden in the file manager. In File Manager, click on the Settings button on the top right corner, a popup will appear. Check the option “Show Hidden Files (dotfiles)” and press “Save”.

Copyright © 2014-2018 All rights reserved.