Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule does not pass ampersands

         

crimsontwo

10:27 pm on Mar 26, 2010 (gmt 0)

10+ Year Member



Hi,

Here's my rule:

RewriteRule ^catalog/([^/]+)/([0-9]+)/([0-9]+)/([^/]+)$ products.php?category=$1&page=$2&per_page=$3&search=$4 [QSA]

For some reason "category" is not properly passed to the PHP script if it contains "&". For instance: mysite/catalog/boots_&_shoes/1/1/

When I print out an array of what PHP receives, I see the following:

Array ( [category] => boots_ [_shoes] => [page] => 1 [per_page] => 1 )

What I am doing wrong? :)

Thanks!

g1smd

10:42 pm on Mar 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Once the URL request is rewritten to a server filepath, the & is being seen as a parameter delimeter. Your parameters become:

products.php?category=boots_[b]&[/b]_shoes[b]&[/b]page=1[b]&[/b]per_page=1[b]&[/b]search=



Either encode the & symbol when used in a URL, or remove/replace the & symbol with something else. I'd get rid of the clumsy _&_ construct and use + or something else instead.

crimsontwo

11:01 pm on Mar 26, 2010 (gmt 0)

10+ Year Member



But I do encode it (in JS). What I actually pass to .htaccess is this: boots_%26_shoes

jdMorgan

11:21 pm on Mar 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Right, but it's now passed in the correct parameter, and that's easier to deal with in the script by using urldecode().

The basic problem is that your URL-scheme does not comply with the HTTP protocol character restrictions and encoding requirements.

Further, the characters set allowed in the URL-path and that allowed in appended query strings is different, but you've assumed them to be identical. RFC 3986 [tools.ietf.org] is worth a read...

Jim