SEO Friendly Redirects with PHP

Twitter Facebook Pinterest Google+ Stumbleupon LinkedIn


With a basic redesign you probably wont have this problem but if you have rebuilt a website even with the same content if the URL’s have changed this will have a huge effect on your search engine presence as you will be starting from scratch. Your links from internal pages may not work, links from external sites wont work and you will lose your pagerank (if it ever mattered anyway.)

A good way to keep your sites listing after a redevelopment is to use a redirect. If you are using an Apache server you can use the .htaccess file to redirect.

Redirect 301 /oldpage.html /newpage.html

But some times this isnt the best way if you have to redirect hundreds of pages. The alternative is to use a header redirect in PHP. Most web based languages such as ASP or RUBY will do the same thing but with different code.


<?php

// make this code the first line
header("Location: /newpage.php",TRUE,301);
// 301 Moved Permanently to newpage.php
?>


Posted by Adi on January 24, 2009

Twitter Facebook Pinterest Google+ Stumbleupon LinkedIn

3 responses to “SEO Friendly Redirects with PHP”

  1. Hutchy says:

    This seems to be a very quick and easy way to redirect in the proper manner. How does it compare in speed though to adding them in apaches htaccess file?

  2. Adi says:

    The good thing about doing this in PHP instead of using a htaccess file is you can redirect all your pages from a database query and ammend a URL. also if you have hundreds of redirects you dont need to worry about having a huge htaccess file.

  3. tmodsw says:

    I have been looking for an example of how to do this for a while, now I can redirect my whole shopping cart system with ease, thank you!

Leave a Reply

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