Redirect to www with .htaccess

The prefix www in web hyperlinks is becoming obsolete but a lot of people still like using it. So in order to avoid a 404 when someone tries to type in a http://yourhomepage.com you will need to setup a redirection to http://www.yourhomepage.com in your .htaccess file. This is the code you will need to enter:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^yourhomepage.com [nc]
rewriterule ^(.*)$ http://www.yourhomepage.com/$1 [r=301,nc]

This also ensures that you don´t lose page rank through links pointing to http://yourhomepage.com instead of http://www.yourhomepage.com

One Response to “Redirect to www with .htaccess”

  1. Redirect to www. with htaccess part II » Hosting Blog » Blog Archive Says:

    [...] In an earlier post I already gave you the plain .htaccess method for enforcing www. [...]

Leave a Reply