Ampersands. I don't want them to be escaped

Discuss practical ways rearrange URLs using mod_rewrite.

Ampersands. I don't want them to be escaped

Postby Guest » Tue Mar 29, 2005 3:10 am

I'm having a little bit of a problem with mod rewrite and its insistance on escaping stuff that I don't want it to. E.g.

Code: Select all
RewriteRule  ^test/([^/]+)/$ test.php?q=$1 [QSA,NC,L]


and test.php is just this:

Code: Select all
foreach ($_GET as $key => $val) {
    print "{" . $key . "} = {" . $val . "}<br>\n";
}


So if I go to the following URL:

Code: Select all
http://www.site.com/test/this+&+that/


I get the following output:
Code: Select all
{q} = {this }
{that} = {}


The ampersand in there has been missenterpreted by the Apache so it thinks that we want to use the following URL:

Code: Select all
test.php?q=this+&+that


But exactly the same happens if I substitute '&' for '%26'.

What I want to happen is to get a URL where 'q' is 'this & that' or more explicitly:

Code: Select all
test.php?q=this+%26+that


Is there a way to do this?
Guest
 

Postby Caterham » Tue Mar 29, 2005 5:37 am

What about
http://www.test.com/test/this+%2526+that
%25 => % in Hex-Code

The ampersand in there has been missenterpreted by the Apache so it thinks that we want to use the following URL:
PHP splits the queryString, not apache
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 22 guests

cron