Redirect non-www traffic to www address

Advertising website addresses without the ‘www.’ is a growing trend. It’s smaller, concise and gives the domain name the first bit of attention. However not all websites are prepared to accept or work using either www or non-www traffic.

The easiest and most consistent way to manage this is to simply decide which is your preferred traffic source (www or non-www) and configuring your website to redirect the traffic.

The steps below detail how to configure a website to redirect non-www traffic to the www address, for example itsupportguides.com will redirect to www.itsupportguides.com and even better any other part of the address will be retrained, such as itsupportguides.com/windows7 will redirect to www.itsupportguides.com/windows7 .

This example is only suitable for Apache hosted websites (which use .htaccess for configuration). You will require write access to the configuration files stored on the web host.

 

How to redirect non-www traffic to www address

  1. Access your web files through the cPanel or FTP access. If using cPanel ensure that the ‘Show Hidden Files (dotfiles) option is selected.
  2. apache-redirectnonwww1
  3. Open the root WWW folder for your website (this is the first folder level for the website)
  4. Look for a file titled ‘.htaccess’ . If it does not exist, create it.
  5. Open the .htaccess text file
  6. Look for a line which says
  7. RewriteEngine
  8. If the line exist, ensure it is followed by ‘on’
  9. You should now have
  10. RewriteEngine On
  11. Add the following code – it says ‘if request doesnt start with www. rediect to http://www etc etc.’
# Redirect non-www traffic to www
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
  1. The .htaccess file should look like the example below
  2. apache-redirectnonwww2
  3. Save the changes to the .htaccess file
  4. Reload your website using the non-www address, it should automatically change to the www. address
  5. Open a random page on your website using a non-www address, it should also automatically change to the www. address.

Was this article helpful?

Related Articles