Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Rule ... need urgent help.

Rewrite rule

         

ketlane

12:04 pm on Jan 20, 2005 (gmt 0)

10+ Year Member



Hi!
I just can't get this rewrite rule to work.

RewriteRule ^(.*).html?(.*)=(.*)$ index.php?arg=$1&$2=$3

It should redirect pages like foo.html?nl=1 to index.php?arg=foo&nl=1

Instead of that, I get
"The page cannot be found". (404 Error)

Does anyone have any clue on how to do this?

Birdman

12:44 pm on Jan 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi ketlane, welcome to WW.

The first thing I noticed it that you did not escape the period in regular expression. Certain characters are reserved for regex pattern matching and they must be escaped if you want to match them literally.

\.html

Then next problem is the fact that RewriteRule doesn't "see" the query string part of the URL. You will need to use RewriteCond to catch the query string.

RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)\.html$ index.php?arg=$1&%1 [L]

The rule above just pins the old query string to the new URL, since it seems that's all you wanted to do.

Be sure to check out the Apache Library [webmasterworld.com] for some good references.

ketlane

2:52 pm on Jan 20, 2005 (gmt 0)

10+ Year Member



Thank you very much.
This solved my problem at the right time.