Your open source for Development and Design

SEO Friendly Redirects with PHP

Filed under: PHP,SEO — Tags: , , — Adi @ 1:32 pm January 24, 2009

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
?>

SEO Apache Mod rewrite

Filed under: Apache — Tags: , , — Adi @ 3:03 pm January 12, 2009

I always tried to avoid using the .htaccess file as it either works really well or will take down the entire site. The code below will work on most sites using apache as long as they have modrewrite turned on and you edit the rules to suit your domain.
You may ready be using a .htaccess file on your server so double check as it may not show up on all FTP programs.

But why do you need to use one, well the short answer is you don’t but the long answer is it can help a lot to stop duplicate content being taken off search engines and in turn help improve your SEO.
For example how often do you see urls like www.bbc.com/index.html ?

The code below will redirect any variation on your homepage to just one. it will add the www. to the domain name and remove the index.html or index.php which ever you might be using.

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

RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html(.*)\ HTTP/ [NC]
RewriteRule .* http://www.somedomain.com/ [R=301,L]

Switch to our mobile site