Dealing with question marks????????

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

Moderator: General Moderators

Post Reply
BigChase
Forum Newbie
Posts: 8
Joined: Sat Oct 15, 2005 4:48 pm

Dealing with question marks????????

Post by BigChase »

Trying to create a .htaccess RewriteRule that will map

question.php?1 to query?number=1

but niether of the following ways to deal with the '?' (question mark) work:

RewriteRule ^question \.php\?1$ query?number=$1
RewriteRule ^question \.php$?^([0-9])$ query?number=$1

How do I deal with the question mark in the pattern without having the regular expression mistake the '?' in the URL as the ? operator?

Thank you.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Code: Select all

"/\? \(escape it\)/"
BigChase
Forum Newbie
Posts: 8
Joined: Sat Oct 15, 2005 4:48 pm

Post by BigChase »

Sorry, I don't know how to read your response. Can you insert it in the example in the original posting. Sorry to be so thick. Thanks.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

\?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Code: Select all

RewriteRule ^question \.php\?1$ query\?number=$1
BigChase
Forum Newbie
Posts: 8
Joined: Sat Oct 15, 2005 4:48 pm

Post by BigChase »

It didn't work when I escaped the question mark, but I see in addition you:

escaped the '.' AND added a space after 'question'

Are both of those necessary?

Thanks.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

RewriteRule     ^question\.php\?([0-9]+)$     query?number=$1
On the left hand side the ^ and $ mean start and end of string. On the right hand side the $ means backreferece (i.e. the bit in the parens on the left).

You pretty much had it right although needed to add a backslash before "?" on the left and also remove some carets and dollars :D
Post Reply