Mod Rewrite Rule for change in URL structure

I am in need of 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

What I came up with isn’t working, but I know I’m close:

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

Any help would be greatly appreciated!

Thanks,

Dennis

Hi Dennis,

That resembles the “Loopy Code” I discuss in my signature’s tutorial. I recommend a read of that but, in summary, You also are unaware that query strings can only be examined (in mod_rewrite) by RewriteCond statements (the tutorial notes that very quickly).

Basically, what you want is to redirect from a usable link to an unusable (human format) link and then ask Apache to devine what you want it to serve.

Instead,

  1. Test whether the {REQUEST_URI} is the original request (best to check the code in the tutorial).

  2. Capture the query string (in whole or parts) then redirect to new format.

  3. Redirect new format to the “servable” format.

The first item is critical as it will prevent code looping.

Regards,

DK