mod_rewrite or PHP bug ? some special chars in _GET vars are just "lost" ...
Posted by: Celluloid (
Date: July 05, 2006 02:08PM


This is somehow a follow-up to my problems with mod_rewrite on wampserver 1.4.x (the "let's put all your matched patterns in lowercase because I feel like it" bug).
=> I've updated to the last version (wampserver 1.6.4) and the rule now works fine, that is :

Options +FollowSymLinks
RewriteEngine On
# RewriteLog "rewrite.log"
RewriteBase /somedirectory/somemore/

RewriteCond %{QUERY_STRING} !vardump
RewriteRule ^img/([^/]*)/w-([0-9]+)-h-([0-9]+)-p-([^-]+)-img-([^.]*)\.(gif|jpg|jpeg|png)$ scriptimg.php?img=$1&w=$2&h=$3&page=$4&vardump=ok%{QUERY_STRING} [R=301,QSA]

In the PHP script (scriptimg.php), $_GET['img'] var now holds the ENCODEDPATH ( = urlencode(base64_encode(SOMEREALPATH)) ) BUT ...
If the $_GET['img'] var holds the urldecoded value of the path ( that's ok, that's how it's supposed to work ), here's the weird thing :
whenever I have some "special" character in the ENCODEDPATH (like "+"winking smiley, I "lost" it in the $_GET['img]

Here's what I got in the rewrite log :
------------------------------------------ - - [05/Jul/2006:14:14:48 +0200] "GET /somedirectory/somemore/scriptimg.php?img===ztDJyNPalJ+Vk5mO5cjR2ZWVx5Kkl5Wbz9PP&w=100&h=80&page=std&vardump=ok HTTP/1.1" 200 6059
for an initial path of :

=> the initial "%3D%3D" are two "=" that I decided to put before the string located between /somedirectory/somemore/img/ and /w-100-h-... that's the start of my encoded path.
=> In the PHP script, $_GET['img'] DOES start by two "=", so the parameter is urldecoded, but the "%2B" character ('+') is void !!
Here's the encoded path without the first two "=" :
ztDJyNPalJ Vk5mO5cjR2ZWVx5Kkl5Wbz9PP
Notice the void between "ztDJyNPalJ" and "Vk5mO5cjR2ZWVx5Kkl5Wbz9PP" => my "+" should be there ...
Of course, if I perform a loop or a var_dump on $_GET['img'] character, #12 is missing ...

Has anyone already encountered the same weird behavior ?

Options: ReplyQuote

Sorry, only registered users may post in this forum.