How To Do A Simple 301 Redirect And A WWW Redirect And It’s SEO Implications

Experts working in SEO often find themselves cast  in the role of an IT professional. Therefore it is my understanding, that without basic knowledge of HTML, CSS and PHP  one should not call himself an SEO specialist. One of the most common of these are the redirects. If you Google it and go to the Wikipedia page you won’t get much smarter in how to actually do it or what it means from an SEO perspective. During my work I had to do many redirects but here we will discuss only the most common ones.

If you are using an advanced CMS (Content Managment System) like WordPress , than just search for a plugin. There is no need to get down this deep if you can avoid it. Ifyou can’t avoid it however the following tutorial will show you howto redirect a static HTML webpage and a dynamic PHP webapge the proper way to preserve all the Linkjuice.

What you need

Total commander for FTP access and Notepad or PSPAad (I prefer PSPAd but it’s a bit more complicated) for writing a single snippet of PHP code. If you don’t know what FTP server or how to access it  then please watch this video tutorial before we begin. It’s only two minutes long.

1., Open your Notepad and then simply copy the following code in it:

header(“HTTP/1.1 301 Moved Permanently”);

2.,As you can see it is a simple PHP script. Don’t forget to substitute whatever is after Location:  with your web address you wish to redirect toCurrently it would redirect to me.Now click save as and then save it as index.php it is important to not to forget the extension from the end of it otherwise it will not work.

3., Now that you have the file  simply access your FTP server and open the directory /public_html this will bring you to the root of your domain. Meaning if your website is called then you are right at the homepage level currently. There probably folders named /cake, /bunny or /whatever sub pages ( you have. Forget them for now.

4., Create a backup of all the files inside the /public_html folder before you do anything!

5., Find the file named index and delete it and replace it with the file we have created before. This will redirect your to the web address you specified earlier. There you go! You just did a simple 301 redirect of a static HTML webpage. Make sure you back up everything and only delete the index file if you are not planning to use it again.

SEO effects

The best thing about a 301 (also known as permanent)  redirect that it keeps as much as 90-99% of the linkjuice of the redirected page and redirecting it to where you like it. If you redirect it within the URL like is redirected to then the domain authority and Pagerank transfer will be really fast, however transferring between URLs ( to can take time.

PHP Canonical Redirect or www redirect

This is the second most often forthcoming redirect. This a bit more complex and your old and home-brew content management systems sometimes require a redirect like this. They are most often written in PHP. What this redirect does, is that it will make your website available both with and without the www. prefix.  It is very easy just  do the same as we did before.

1.,  Use this code and this time you don’t even have to change anything in it:

if (substr($_SERVER[‘HTTP_HOST’],0,3) != ‘www’) {
header(‘HTTP/1.1 301 Moved Permanently’);
header(‘Location: http://www.’.$_SERVER[‘HTTP_HOST’]

2., Instead of deleting the the index file this time just insert this code into the index.html or index.php file at the very top before everything else. You just did a PHP Canonical Redirect! How great is that.

It is important to note , that if you are not sure about this or too much is at risk, then you should seek an expert’s help. Sadly we often don’t have this luxury.

SEO effects

Same as before the link juice is transferred without problem authority and Pagerank is unaffected after a brief initial transition. Some might claim to a redirect a www-less version of the webpage is much better from a usability standpoint but it is wrong. The best user experience is guaranteed , if your visitors, direct traffic can reach you using both with www and without.

302, 307 redirects and any other forms of redirects should be avoided at all cost except if you are planning to lose the domain authority and Pagerank and accumulated Linkjuice on purpose. It was largely helpful to save the traffic from spammed websites and websites with unnatural link portfolio but since we can easily disavow links in WMT(Google Webmaster Tools) it is rarely used nowadays.

Javascript redirect should be avoided as well as it does not pass Linkjuice or DA or PR at all.

Leave a comment

Your email address will not be published. Required fields are marked *