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.