2015-01-21 63 views
2

我有这样一个URL: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

Apache将多个/拆分成单个/RewriteRule。改为使用RewriteCond

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

谢谢@anubhava但是当我使用这个规则时,php中的url参数是空的!为什么? – 2015-01-21 07:41:33

+0

对不起,我的错误。它应该是'%1'而不是'$ 1'。立即尝试更新的代码。 – anubhava 2015-01-21 07:46:44

+1

非常感谢你,你的代码像一个冠军:) – 2015-01-21 07:59:46