Redirect Non www to www URL

Share this article

non www to www 03When we build websites to serve our users, our aim is simple that is to keep the site simple. Now, most often our users type the address of the website sometimes with www. and sometimes without www.

Now, why in the world would someone not type www and try to visit a website. Well, you cannot blame users for that and look up for a solution to keep our users who come into the site without typing in the www prefix with the URL.

Our focus should always be around the users and keep the site navigation friendly. Asking our users of forcing hem to enter prefix with our site is not a solution, since not every user is going to follow the guideline. Instead, we will have a solution implemented to handle the users who do not prefix www.

There are loads of articles that talk about how to achieve a successful redirection of non-www URL to www URL. I have seen too many complicated steps involved in to implement a simple solution.

Procedure 01:

  1. Go to the public_html folder [root of the site] of your hosting
  2. Locate htaccess.txt and rename it to .htaccess
  3. Now open it and
    1. Remove hash symbol # from “RewriteEngine On” to turn the rewriting engine on
    2. Add the following code to redirect non-www URL to www URL Ex: URL will be redirected to
RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Procedure 02:

Here is a quick way to achieve it:

  1. Go to the public_html folder [root of the site] of your hosting
    • if multiple domains are hosted on the same hosting plan, go to the root folder of the domain you are willing to redirect.
  2. Locate .htaccess file, if you do not find it look for htaccess.txt. If both are not found create a new file with a name .htaccess
  3. Now open this file and add the following code under this file
RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Did you Find it helpful?,drop a line and share it forward to help others. Have a nice day.