Page 1 of 1

Mod Rewrite with Question Mark

Posted: Fri Aug 21, 2009 12:19 pm
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.

Re: Mod Rewrite with Question Mark

Posted: Fri Aug 21, 2009 1:10 pm
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.

Re: Mod Rewrite with Question Mark

Posted: Fri Aug 21, 2009 1:50 pm
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.

Re: Mod Rewrite with Question Mark

Posted: Fri Aug 21, 2009 2:02 pm
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.

Re: Mod Rewrite with Question Mark

Posted: Fri Aug 21, 2009 3:10 pm
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.