.htaccess重写远程图像位置

时间:2011-03-30 17:43:35

标签: .htaccess mod-rewrite

下面的.htaccess我可以从 http // mysite / folder / test.jpg 重写图像位置到 http // mysite / test.jpg

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^pic.jpg /folder/pic.jpg

但是当我尝试使用远程站点时

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^img.jpg http/remotesite/img.jpg

我无法将其重写为http // mysite / img.jpg,因为它被重定向到原始位置而我的问题是,是否可以使用.htaccess重写远程图像位置?

感谢

解决

使用php readfile()

 <?php
 header("Content-Type: image/jpeg");
 $img = $_GET['img'];
 $url =  "http://remote/image.php?img=".$img;
 readfile("$url");
 ?> 

和.htaccess

RewriteEngine on
RewriteBase /
RewriteRule ^(*.jpg)$ images.php?img=$1[L]

1 个答案:

答案 0 :(得分:2)

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^img.jpg http://remotesite/img.jpg