Webmaster Tutorials

Force “www” into your URLs

Posted on April 21st, 2010

Use .htaccess files to force the www into the URLs of your site – great for SEO and for consistency

Force “www” into your URLs

Posted on April 21st, 2010

Force "www" into your URLsWhen it comes to building a web site there are many important factors which need to be taking into consideration, some of which are often overlooked. One example of these is your sites URL. We’re not talking about the domain you choose to host your site on or what your site is called but more to do with the “www” part of your sites URL.

In this quick tutorial we’ll show you how to force it so that your web site URL is always using “www”. Doing this means that the non-www version of your URL needs to be redirected to this version. Doing this forced redirection is a very easy task and doesn’t take long at all.

All you need is to copy and paste the following code snippet into a file called “.htaccess” placed at the root of your web site. If this file does not already exist, create it. If however you already have a htaccess file in place you should copy and paste the following code and place it at the top of your htaccess file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^wmtutorials.com$ [NC]
RewriteRule ^(.*)$ http://www.wmtutorials.com/$1 [R=301,L]

In the code above you will of course need to replace “wmtutorials.com” with your own sites domain name.

The opposite of this would be to forcefully remove the “www” which then makes the URL slightly shorter. It is of course your choice but the important thing is this: once you’ve picked which style you’d prefer to use try to stick to it.

...