Home » Blog

Migrating from Drupal to Wordpress without losing indexation

3 February 2009 2 Comments

Moving this site from Drupal 4.x to Wordpress 2.7, I was obviously concerned with losing indexation of my old Drupal URLs from search engines.

As I had not set up clean URLs on my Drupal website for a lot of my content, I needed a quick and easy way of ensuring that any traffic destined for one of my Drupal pages firstly found it’s way to the original content (as not everything has moved over to the new site) and secondly informed my users that the site had been moved.

Enter the 301 redirect, the safest way to redirect both users and search engines.

As I was not using clean URLs, the majority of my Drupal hits where coming in the form http://www.planetofthepenguins.com?q=node/… . It’s the q= that’s key – Wordpress doesn’t use this parameter and so I can safely assume that when I see it, it means the browser wanted a page from the old site.

So, having pointed a new subdomain (http://old.planetofthepenguins.com) at my old Drupal site, the code to perform the automatic redirection is simple …

<?php
$drupalq = $_GET['q'];
if ($drupalq){
header(”Status: 301 Moved Permanently”);
header(”Location:http://old.planetofthepenguins.com?q=” . $drupalq);
exit;
}
?>

This code

  1. Grabs the “q” parameter from the URL into a variable
  2. Checks this variable and if it has been set
  3. Writes a 301 redirect to the HTTP return header
  4. Writes a location into the HTTP return header
  5. Prevents the rest of the page from being rendered

All that remains now is to put a prominent message on my old site that I have moved to a new platform and provide my users with a link to click.

Oh, and set up my Permalinks in Wordpress!

Related posts:

  1. Upgrading to Wordpress 2.8.4 – Easy, and now vital! September 5th saw the launch of an exploit based attack...
  2. Adding Quotes to Wordpress If you are in the market for a quick and...
  3. Drupal in 57 seconds As the “tech” side of the blog is heating up,...
  4. Linux.com: Drupal 4.7 – Next Generation CMS Drupal is a content management system (CMS) built on the...
  5. WhiteHouse.gov Goes Drupal My favourite piece of open source CMS software has added...

2 Comments »

  • Linus said:

    Dude, you’re my hero!

  • RaiulBaztepo said:

    Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I’v just started to learn this language ;)
    See you!
    Your, Raiul Baztepo

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.

Security Code: