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 http://example.com to http://www.example.com/ 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} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

4. Make sure to change example.com to your own domain name and save the file.
5. Now whenever you type your domain as example.com it will automatically redirect to www.example.com 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 Webxen.com. All rights reserved.