Non-www Redirects & More
This is a quick tutorial showing you how to redirect non-www urls, i.e. http://alexybecker.com/ to http://www.alexybecker.com/.
First of all, let me emphasize why it’s important to have uniform url linking structure. The easiest way to explain this is to break it down to you in the simplest of terms. Search engines like google, yahoo, and msn think that http://alexybecker.com/ and http://www.alexybecker.com/ are two completely different pages, therefore, not having non-www redirects implemented will give you an inherent duplicate content penalty; that is arguably the biggest search engine traffic killer.
Before I begin this tutorial I should warn people that I’m currently using an Apache based server and thus will be using an .htaccess file that will tell the server to redirect visitors and search engines alike that both non www urls and www urls are the same page. Some servers require different steps to properly setup a non-www redirect. For more information on non-Apache www redirects please click here.
Your first step is to see if you have an .htaccess file already on your web server. If you do, download it to your desktop and open it with your favorite editor. If you do not have an .htaccess file, open up your favorite editor and create a new file and save it as .htaccess – with the period! Now, copy the code pasted below exactly as written below, replacing all instances of thecreditco with your websites url. OK, so now that you know why we are either adding code to our original .htaccess file or creating a new one, let’s get down to the actual code.
Here is the actual .htaccess code if you are interested in downloading my actual .htaccess file, please click here.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^thecreditco.com
RewriteRule (.*) http://www.thecreditco.com/$1 [R=301,L]
ErrorDocument 404 http://www.thecreditco.com/
You will notice that I have also included a line of code for a 404 redirect to my main website (the 4th line of code). For those of you who are unfamiliar with 404 redirects, they tell the server to redirect users to the designated 404 redirect url or the custom 404 redirect page. For example, http://www.thecreditco.com/abcdefghijklmnopqrstuvwxyz.html does NOT exist, but if you click that url, it will redirect you to my home page instead of a broken page. It’s a good idea to have it in your .htaccess file!
I told you it was a simple tutorial and I think it is. I’m assuming that if you are interested in learning www redirects and 404 redirects you are familiar with basic web publishing and server management. If you have any questions, don’t hesitate to ask!