section31 Posted November 30, 2005 Share Posted November 30, 2005 I have some issues with modrewrite and the ampersand. I encoded the ampersand to %26, but it doesn't seem to work. View the following php scripts to replicate the issue. Using Simple Get Request http://section31.us/temp/modrewrite/get.php?foo=a%26b >prints Array ( [foo] => a&b ) Using Mod Rewrite (RewriteRule ^foo/(.*) get.php?foo=$1) http://section31.us/temp/modrewrite/foo/a%26b >prints Array ( [foo] => a [b] => ) Anyone have any experience using an ampersand with mod rewrite. Quote Link to comment Share on other sites More sharing options...
TweezerMan Posted November 30, 2005 Share Posted November 30, 2005 From what I've been able to find on the internet, this is a known issue with mod_rewrite that is currently not fixed. Depending on your script, you may be able to work around the issue with one of these options: 1) Double-URL-encode ampersands As you noted above, ampersands ('&') can be encoded in a URL as '%26'. Encode the '%26' as well, with '%' encoded as '%25'. This would result in the ampersand being replaced with '%2526'. Since mod_rewrite only perform one pass in decoding URLs, the string '%2526' will be decoded into '%26', which will then be passed correctly to your script. 2) Change the query string argument separator in PHP In URL query strings, parameters can be separated with '&' or ';'. By default, PHP uses '&' to separate multiple parameters in a URL's query string. You can configure PHP to use ';' instead by adding the following to your .htaccess file: >php_value arg_separator.input ";" 3) Parse the query string yourself The query string that was submitted in the URL to your script will be present in the PHP global variable $_SERVER['QUERY_STRING']. Your script could read the query string directly and parse it into variables in however manner you see fit. Hope this helps... Quote Link to comment Share on other sites More sharing options...
section31 Posted December 13, 2005 Author Share Posted December 13, 2005 Thanks David. Your first method will do nicely. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.