Author image
Senior Mind

Mod rewrite rules and querystring parameters in Drupal

Just a quick one this, and not strictly Drupal related - but might save you some time when you are writing modrewrite rules to rewrite legacy URLs.

The problem : We had a whole bunch of legacy URLs in the format index.php?Page=SomePageHere which we needed to rewrite to point at some shiny new Drupal URLs.

A simple RewriteRule wasn't working, and after a bit of digging we discovered you can't reference the querystring within a RewriteRule ...

The solution is to use RewriteConditions, so you end up with something like

 RewriteCond %{QUERY_STRING} Page=SomePageHere
RewriteRule ^index.php$ new-page-url-here? [R=301,L]

And jobs a good un!