views:

752

answers:

3

Hey there!

I want to simply not use ampersand in my URL so I can pass ampersands further down into my system when a file is requested. The problem is Apache deals with it differently. I don't know how

I already rewrite the requested file to index.php?url=$1 so I can see what it was, but if it has an ampersand in there, it can't continue past it!

how can I escape the ampersand or turn it into it's hex equal (%26)?

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>`
+1  A: 

Add

RewriteRule ^(.*)\&(.*)$ $1\%26$2

To your rewrite rules.

Matthew Iselin
hmm, this seems to break the !-f condition from above and now all external files arn't working on the server
Supernovah
Where did you put the RewriteRule line?
Matthew Iselin
A: 

Try putting this rule above yours:

RewriteRule ^([^&]*)&(.*) $1\%26$2 [N]
Gumbo
A: 

In addition if you want to send back to the browser a redirect with the ampersand in the URL you can add the [NE] flag to the end of the RewriteRule.

RewriteRule ^/(.*) /index.php?p=yourpage_\%26_something_else [NC,NE,R=301,L]
atwskris