I have the following code in my .htaccess file
RewriteEngine on
RewriteRule ^thumbnail/(.*).png thumbnail.php?url=$1 [NC]
And what that does is it turns
http://mydomain.com/thumbnail.php?url=http%3A%2F%2Fwww.example.com%2F
Into
http://www.mydomain.com/thumbnail/http%3A%2F%2Fwww.example.com%2F.png
But when I echo out the url variable in the thumbnail.php file it returns
http:/www.example.com/ NOT http://www.example.com/
Where did the other / go?
Because the
http://www.example.com/is part of the URI path (as opposed to being part of the query string), apache automatically normalizes the path, thus removing multiple consecutive slashes. For example, if you tried to go to:And then print out the value of
url, you’d getfoo/bar.pngbecause before the URI even gets to mod_rewrite in the processing pipeline, the extra slashes are cleaned out.Alternatively, you could remove the
http://part and add that in the rewrite:Then your url would just be:
And when you print out the value of
url, you’d gethttp://www.example.com/.png