如何将图像URL作为参数传递给.htaccess

时间:2013-12-21 18:57:07

标签: php apache .htaccess mod-rewrite

这是我的.htaccess代码

Options all -Indexes

<Files .htaccess>
order allow,deny
deny from all
</Files>

<IfModule mod_rewrite.c> 
Options +FollowSymLinks 

RewriteEngine On 
RewriteBase / 

RewriteRule ^thumb/(.*)$ thumb.php?imagePath=$1 [B]

</IfModule>

如果我输入的网址为http://mydomain.com/thumb/image1.jpg,则会将其传递给thumb.php?imagePath=image.1,并且工作正常。

假设我输入的网址为http://mydomain.com/thumb/http://otherwebsite.com/images/image1.jpg

然后显示404错误。请帮我解决这个问题

我使用的编码也很像http://mydomain.com/thumb/http%3A%2F%2Fotherwebsite.com%2Fimages%2Fimage1.jpg

相同我得到404错误。请帮我理清一下。

2 个答案:

答案 0 :(得分:1)

为什么要在规则末尾添加/

试试这个:

Options all -Indexes

<Files .htaccess>
order allow,deny
deny from all
</Files>

<IfModule mod_rewrite.c> 
Options +FollowSymLinks 

RewriteEngine On 
RewriteBase / 

RewriteRule ^thumb/(.*)$ thumb.php?imagePath=$1 [B]

</IfModule>

答案 1 :(得分:1)

要使用http://参数,您需要使用THE_REQUEST变量捕获URI。 THE_REQUEST变量,表示Apache从您的浏览器收到的原始请求

尝试此规则:

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{THE_REQUEST} \s/+thumb/(\S+) [NC]
RewriteRule ^ thumb.php?imagePath=%1 [B,L,NE]
相关问题