Forum Moderators: phranque

Message Too Old, No Replies

How to handle & in the Query String Value- Help Please

How to handle & in the Query String Value in ModRewrite Rule

         

Raj123

2:10 pm on Oct 25, 2006 (gmt 0)

10+ Year Member



We are in the process of making user friendly urls.

I am using the following rules.

RewriteRule ^/appmanager/bg/main/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /appmanager/bg/main?_nfpb=true&_state=maximized&_pageLabel=$1&_windowLabel=$2&categoryId=$3&categoryName=$4 [NE,PT,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /appmanager/bg/main\?_nfpb=true&_state=maximized&_pageLabel=([^/]+)&_windowLabel=([^/]+)&categoryId=([^/]+)&categoryName=([^/]+)\ HTTP/
RewriteRule ^/appmanager/bg/main$ [%{HTTP_HOST}...] [NE,R=301,L]

The categoryName parameter in the Query String has got values with "&" and with out "&". Example. "Business Licenses & Permits".
The string "& Permits" protion is getting truncated and the string portion "Business Licenses" is only getting displayed instead of "Business Licenses & Permits" in the Page. How to handle "&" in the ModRewrite Rule

You help is highly appreciated. Thanks in Advance.

jdMorgan

3:06 am on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll either have to handle those in a case-by-case basis in the rewrite code, or get rid of all "&" characters in your query strings. How you do that most easily depends on how your site is set up; You can add a new database entry to separate the "display URL" from the "page title" concepts. You can use preg_replace in PHP to change all occurances of "&" in page titles to "and" in URL query strings, and then back again when that URL/query is received, etc.

I suppose you could also use PHP to encode those "&" characters, so that the RewriteCond would see "%26" instead of "&". Or even double-encode them if necessary, resulting in "%2526".

Jim

Raj123

12:49 pm on Oct 27, 2006 (gmt 0)

10+ Year Member



Jim Thank you so much for your valuable feedback.