1

I am trying to create a mod rewrite rule to correctly change an existing url structure that looks like this:

Old: somesite.com/scripts/data/database.cgi?ArticleID=29154&report=SingleArticle&file=Data

Into something that looks like this:

New: somesite.com/oldarticle/id29154.htm

All I need basically is to take the ArticleID and insert it into the new url structure. What I came up with isn't working, but I know I'm close:

RewriteEngine On
RewriteRule ^(.*)/database\.cgi\?ArticleID=([0-9]+)&report=SingleArticle&file=Data$ /oldarticle/id$1.htm [R=301,NC,L] # Permanent Move

I have tried many variations of the above, and am probably missing something in the initial string needing to be rewritten. Any help/suggestions would be greatly appreciated!

1 Answer 1

1

The query string isn't part of the string you're matching in the RewriteRule. Instead, you'll need something like this:

RewriteCond %{QUERY_STRING} report=SingleArticle [NC]
RewriteCond %{QUERY_STRING} file=Data [NC]
RewriteCond %{QUERY_STRING} ArticleID=([0-9]+) [NC]
RewriteRule ^.*/database\.cgi /oldarticle/id%1.htm? [R=301,NC,L]

I split up the conditions so that the order of the query string isn't hardcoded, but not sure if that matters to you.

1
  • Thanks for breaking it up. Makes it easier for me to follow, and yes, actually, I would prefer the order of the query string not be hardcoded. Thanks!
    – perdrix
    Oct 2, 2013 at 18:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .