As I mentioned, I just converted from Drupal to WordPress, and one of the most difficult parts of the conversion was figuring out how to redirect Drupal’s old urls to the new equivalents in WordPress. I’d taken care to carry over ID values intact, so the mapping was easy, and Apache should have been quite capable of doing the url translation for me, but it took a fair bit of trial and error to get it to work right.
Here’s the file that finally worked:
#
# Apache/PHP/Drupal settings:
#
# Various rewrite rules.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
# Rewrite drupal urls to worpress
RewriteCond %{QUERY_STRING} ^q=node/(.+)$
RewriteRule ^(.*)$ http://blog.componentoriented.com/?p=%1 [R=301,L]
# Forward RSS feed
RewriteCond %{QUERY_STRING} ^q=rss.xml$
RewriteRule ^(.*)$ http://blog.componentoriented.com/?feed=rss2 [R=301,L]
RewriteCond %{QUERY_STRING} ^q=atom/feed$
RewriteRule ^(.*)$ http://blog.componentoriented.com/?feed=rss2 [R=301,L]
</IfModule>
Notice the use of RewriteCond before RewriteRule. When I originally tried this, I used only the RewriteRule statement and tried to match the query string in the first part of the RewriteRule statement. Needless to say, it didn’t work.
The problem turned out to be that RewriteRule just wouldn’t match query strings (which is where the node ID was), and when I figured out how to use RewriteCond, that turned out to be exactly what I needed. The %1 instead of $1uses the value that was matched in the previous RewriteCond statement rather than the matched value in RewriteRule.
Finally, you can see that I also forwarded the old Drupal RSS feeds. If you’re converting from Drupal, this should work for you, and if you’re converting from anything else, hopefully this example will help a bit.
I can't think of the specific plugin name but you can use a WP plugin to do all this for you and convert the database as well….
Posted by htaccess redirect | 10. Sep, 2008, 9:57 amIf you find it, let me know. Otherwise, this seems to work reasonably well. About the only place where the .htaccess solution appears not to do the trick is if there's an automated system accessing the URL – some seem to follow the 301 redirect, and others don't. If the plugin solution works better, that might be worth a look.
Posted by dlambert | 10. Sep, 2008, 11:06 amYeah i would also be interested if you manage to find that plugin, ive got two drupal sites that ive wanted to transfer for ages but been scared to do so… Im going to give this htaccess a try on a test server and see if i cant iron out the problems you mentioned… I hate htaccess… its voodoo
Posted by color_chart | 10. Nov, 2008, 9:33 amI still have not seen that plugin, but I haven't really been looking for it because I've had no issues whatsoever with the htaccess script above. Prior to discovering the bit about RewriteCond vs. RewriteRule, I'd have agreed that htaccess was voodoo, but once I discovered that little gem, it almost makes sense!
Good luck with your conversion!
Posted by dlambert | 10. Nov, 2008, 10:15 amYeah i would also be interested if you manage to find that plugin, ive got two drupal sites that ive wanted to transfer for ages but been scared to do so… Im going to give this htaccess a try on a test server and see if i cant iron out the problems you mentioned… I hate htaccess… its voodoo
Posted by color_chart | 10. Nov, 2008, 2:33 pmI still have not seen that plugin, but I haven't really been looking for it because I've had no issues whatsoever with the htaccess script above. Prior to discovering the bit about RewriteCond vs. RewriteRule, I'd have agreed that htaccess was voodoo, but once I discovered that little gem, it almost makes sense!
Good luck with your conversion!
Posted by D. Lambert | 10. Nov, 2008, 3:15 pmThanks, I've been trying to get Drupal RSS feeds to Feedburner and all the htaccess rewrite's I found failed to work… your's was the first to work. Obviously I used a 302 rewrite, not a 301.
Posted by Fran | 14. Feb, 2010, 7:03 pmI'm glad it worked for you, Fran. Thanks for stopping by.
Posted by D. Lambert | 14. Feb, 2010, 9:26 pm