Apache mod_rewrite 将双斜杠转换为单斜杠

Apache mod_rewrite converts double slashes to one slash

我有一个 URL 这样的:

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

所以我在这个问题的帮助下创建了一个规则

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

但是当我在 htaccess 文件中使用此规则并像这样使用相同的 URL 时:

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

我参数中 http: 后的结果双斜杠转换为单斜杠!所以我在 php 中的第一个参数变成:

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

你能帮帮我吗?

A​​pache 在 RewriteRule 中将多个 / 剥离为单个 /。使用 RewriteCond 代替:

RewriteCond %{REQUEST_URI} ^/img\.php/(.+?\.(?:jpe?g|png))$ [NC]
RewriteRule ^ img.php?url=%1 [L,QSA]