Redirect Wordpress Posts to Drupal

If, like me you've migrated your blog / site from Wordpress to Drupal you will probably want to arrange to 301 redirect all your Wordpress links to their new Drupal equivalents.

The Redirect module can be used to handle the redirection, but you might want a way to automated the process of entering the redirects.

If so, what you need is the Redirect Import module along with a CSV file containing the old urls and the new ones.

You can create an appropriate CSV file automatically by joining the old Wordpress "posts" table to the new Drupal "node" table with the following SQL statement. The SQL statement will need a little editing for your configuration (and you need to make sure that your sql client can access both databases). This code assumes mySql but it will probably work on any other sql database. Standard disclaimer, take backups, run at your own risk and especially, don't come crying to me if something goes wrong...

 

SELECT concat('blog/?p=',id), concat('node/',nid), post_title, title FROM `your_wordpress_db`.`wp_posts` wp 
left join `your_drupal_db`.`node` dp on dp.title = wp.post_title
where dp.title is not null and dp.title != ''

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
To prevent automated spam submissions leave this field empty.