we recently migrated a site from a custom CMS to drupal. In an effort to preserve some links that our users bookmarked (we have about 120 redirects) we would like to forward the original URLs to a new URL.

I have been searching for a couple days, but can't seem to find anything simple to what I need.

We have existing URLS that contain one or more query strings, for example:

and we would like to forward to the new location:

I started using:

RewriteEngine On  
RewriteRule ^/article\.php?issue_id=12&article_id=275$ http://foobar.edu/content/super-happy-fun-article [R=301,L]  

This, however, does not work.

A simple RewriteRule works:

RewriteRule ^test\.php$ index.php  

It is unclear to me how I need to use {QUERY_STRING} with multiple

Basically it's 120 simple redirects that go from one existing URL to a new one. I don't need ranges [0-9], because there is no sequential order to existing URLs.

Perhaps I can do what I need with RewriteMap and a simple text file that contains a line like this:

index.php?issue_id=12&articleType_section=0&articleType_id=65 http://foobar.edu/category/fall-2008

If anyone has any idea on using mod_rewrite to accomplish this or if there is a better, or more simple mod, I am open to that as well.



It's not really efficient to make a rewrite rule for every possible outdated link. So probably your best option is to issue a php redirect to the new link. Create a function 'generateLink' that parses the $_REQUEST and creates the 'new' link, then issue a header("Location: $newLink", '', 301). Call generateLink() at the top of article.php, before any output is generated (otherwise header() will fail)

  • Thanks, that's what I was afraid of. In my scenario, I was less concerned about performance and more concerned with getting a base solution up. Much appreciated! – Derek Jan 18 '11 at 15:20

If you need to do it quick, can't you just write a new article.php that forwards to the correct drupal page?


$locations[12][275] = 'content/super-happy-fun-article';
$issue = $_GET['issue_id'];
$article = $_GET['article_id'];
 $go = $locations[$issue][$article];
 $go = 'broken_link'

header( 'Location: http://www.yoursite.com/'. $go );

RewriteRules (by default) only work on the URL part, not on the query part (the part behind the ?). To build rules which fire depending on the query part you need to set conditionals for the query string

RewriteCond %{QUERY_STRING} ^issue_id=12&article_id=275$
RewriteRule ^/article\.php http://foobar.edu/content/super-happy-fun-article [R=301,L]

To get something like you requested.

But with 120 redirects, the idea of using a customized article.php is better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.