Apache mod_rewrite将双斜杠转换为一个斜杠

时间:2015-01-21 06:57:02

标签: regex apache mod-rewrite

我有这样的网址:

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

所以我借助这个问题Apache mod_rewrite complex URL regex

创建了一条规则
RewriteRule  ^img.php\/(.+?(?:\.jpg|\.png))$  img.php?url=$1

但是当我在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
你可以帮我吗?

1 个答案:

答案 0 :(得分:2)

Apache在/中将多个/删除为单个RewriteRule。请改用RewriteCond

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