Mod Rewrite with Question Mark

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
target
Forum Newbie
Posts: 7
Joined: Thu Oct 18, 2007 9:47 am

Mod Rewrite with Question Mark

Post by target »

Hi, I'm trying to do a redirect with Mod Rewrite in .htaccess:

RewriteRule ^folder/([0-9]+)-([a-zA-Z0-9\-]+)\?(.*) folder/page.php?id=$1&shortname=$2&$3 [L]

So
http://mydomain.com/folder/1-word?status=success should rewrite to
http://mydomain.com/folder/page.php?id= ... us=success
but this isn't working. If I switch the question mark to a comma (without escaping) then I can use a comma instead of the question mark, but that makes for an odd-looking URL, I'd rather use the standard question mark format. Are question marks not valid in this scenario?

Thanks for any help you can offer.
fizix
Forum Newbie
Posts: 10
Joined: Fri Aug 21, 2009 12:26 pm

Re: Mod Rewrite with Question Mark

Post by fizix »

I'm not very good with regex but why do you have "\-" here:

Code: Select all

RewriteRule ^folder/([0-9]+)-([a-zA-Z0-9    \-     ]+)\?(.*) folder/page.php?id=$1&shortname=$2&$3 [L]
If nobody in this forum can help you, I'd recommend having an admin move your post to the regex forum.
target
Forum Newbie
Posts: 7
Joined: Thu Oct 18, 2007 9:47 am

Re: Mod Rewrite with Question Mark

Post by target »

I needed to include the hyphen so that argument can contain numbers, letters and hyphen. That part works. It's just the question mark part that has issues.
fizix
Forum Newbie
Posts: 10
Joined: Fri Aug 21, 2009 12:26 pm

Re: Mod Rewrite with Question Mark

Post by fizix »

target wrote:I needed to include the hyphen so that argument can contain numbers, letters and hyphen. That part works. It's just the question mark part that has issues.
As far as I know that should work... Like I said, maybe try the regex forum.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Mod Rewrite with Question Mark

Post by requinix »

RewriteRule works against the requested filename, not the entire request URI.

Code: Select all

RewriteRule ^folder/(\d+)-([a-zA-Z\d-]+)$ folder/page.php?id=$1&shortname=$2 [L,QSA]
QSA will automatically append the query string.
Post Reply