Not matching ? as literal

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
susb8383b
Forum Newbie
Posts: 2
Joined: Wed Nov 19, 2008 8:19 am

Not matching ? as literal

Post by susb8383b »

Hi,

I'm pretty new to regex and still trying to figure out how to do simple things.

Can anyone explain to me why this redirect works in my .htaccess file (I'm on Apache):

When I use the url:
http://www.mydomain.com/blah.htmlRD=123

this redirect works properly:
RewriteRule ^([^/]+)\.htmlRD\=123$ test22.php?q=$1 [L]

BUT when I use the url
http://www.mydomain.com/blah.html?RD=123

This redirect gives me a 404 error blah.html not found:
RewriteRule ^([^/]+)\.html\?RD\=123$ test22.php?q=$1 [L]

The only difference between the two is that I added ? before RD. I thought I can use a question mark as a literal if I escape it with \ so I don't understand why the second example doesn't work.

Thanks.
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Re: Not matching ? as literal

Post by GeertDD »

This is not a regex problem actually. The thing is that RewriteRule does never match the query string.
Note: Query String

The Pattern will not be matched against the query string. Instead, you must use a RewriteCond with the %{QUERY_STRING} variable.

http://httpd.apache.org/docs/2.0/mod/mo ... ewriterule
susb8383b
Forum Newbie
Posts: 2
Joined: Wed Nov 19, 2008 8:19 am

Re: Not matching ? as literal

Post by susb8383b »

Bingo!

Thank you so much!

--Susie
Post Reply