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
- Grabs the “q” parameter from the URL into a variable
- Checks this variable and if it has been set
- Writes a 301 redirect to the HTTP return header
- Writes a location into the HTTP return header
- 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!
Dude, you’re my hero!
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