Forum Moderators: phranque

Message Too Old, No Replies

& symbol size creating problem in rewrite

excludes the variable value after & symbol

         

phparion

7:50 am on Apr 28, 2007 (gmt 0)

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



Hi

I am working with mod rewrite with the following rule

RewriteRule ^([^.]+)/$ category_har.php?CatName=$1 [T=application/x-httpd-php]

it works fine for all category names if they have even single, double quotes etc but if some category has & symbol in its name then I get wrong value in CatName variable sent from htaccess

e.g

domain.com/books-&-pens/

this will give me

CatName=books-

and not the rest of the portion.

Can anybody help please how to get full value including & symbol?

thanks

phparion

3:14 pm on Apr 28, 2007 (gmt 0)

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



I have solved my problem by exploding the URL and with few string function to get values from the URL directly BUT it is not the perfect way to do it, I am terribly confused that why does not apache transfers me the complete variable value from query string because I know & symbol separates the query string variable value pairs BUT I am sending the whatever is found after forward slash in my htaccess therefore I believe I must get complete variable-value pair.

Many thanks in advance for shedding light on this matter.

jdMorgan

7:10 pm on Apr 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Simply put, "&" is a reserved character, and you may not use it in a query parameter unless you encode it as "%26 " in the link. When the browser sends this, it will be double-encoded for transmission as "%2526". Then when it is unencoded for use in .htaccess, it will return to "%26", and your script can unencode it once more to yield "&".

Otherwise, as you have observed, Apache takes the "&" to indicate the end of one query parameter, and the beginning of another, as required by the standard cgi query-handling rules.

Jim