开发者

tweaking image urls apache

开发者 https://www.devze.com 2023-02-01 03:52 出处:网络
I have a image hosting server, and i run multiple blogs were most of the images are shared and/or reused.

I have a image hosting server, and i run multiple blogs were most of the images are shared and/or reused.

this is wha开发者_开发技巧t i wanna achieve

<img src="http//www.imagehost.com/demo1.jpg" /> - is the original place where the image is hosted

I want to tweak the "src" on "myblog" to look like = <img src="http//www.myblog.com/demo1.jpg" />

anything that can help me attain this.


There are few ways you could do this - none of which include apache. Apache can't spoof a root URL, which is what you are trying to do. You could create a file on your website (I'll use PHP for example) to fetch the remote file contents:

# get_file.php
$file = $_GET['file'];
$contents = file_get_contents('http://www.imagehost.com/'.$file);
header('content-type: image/jpg');
echo $contents;

you'll need to enable remote file requests in your apache config for this method... <img src="http://myblog.com/get_file.php?file=image.jpg" />

You could spoof preetier using .htaccess

# .htaccess
# after all other directives
RewriteRule /images/(.+)$ http://www.imagehost.com/$1 [L]

Then <img src="http://myblog.com/images/image.jpg" />

In this case, you can never actually access myblog.com/images though...

0

精彩评论

暂无评论...
验证码 换一张
取 消