Apache mod_rewrite converts double slashes to one slash

依然范特西╮ 提交于 2019-12-23 20:33:21

问题


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?


回答1:


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]


来源:https://stackoverflow.com/questions/28061289/apache-mod-rewrite-converts-double-slashes-to-one-slash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!