Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache mod_rewrite converts double slashes to one slash

i have a URL like this:

http://example.com/img.php?url=http://example2.com/path/to/image/name.jpg

so i created a rule by help of this question Apache mod_rewrite complex URL regex

RewriteRule  ^img.php\/(.+?(?:\.jpg|\.png))$  img.php?url=$1

but when i use this rule in htaccess file and use same URL like this:

http://example.com/img.php/http://example2.com/path/to/image/name.jpg

in result double slashes after http: in my parameter converts to one slash! so my first parameter in php becomes:

http:/example2.com/path/to/image/name.jpg

can you help me please?

like image 741
Hamid Zamani Avatar asked Oct 13 '25 01:10

Hamid Zamani


1 Answers

Apache strips multiple / into single / in RewriteRule. Use RewriteCond instead:

RewriteCond %{REQUEST_URI} ^/img\.php/(.+?\.(?:jpe?g|png))$ [NC]
RewriteRule ^ img.php?url=%1 [L,QSA]
like image 141
anubhava Avatar answered Oct 14 '25 16:10

anubhava