Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite image path

How can I rewrite the image path on my website?

i.e. on imagesite.com/images I host my images and on website.com I have my website.

On website.com I use the images hosted on imagesite.com/images. Of course the URL on website.com is pointing to imagesite.com/images, is there some way that I can make it look like the images are hosted on website.com?

like image 688
Display name Avatar asked Apr 09 '26 22:04

Display name


1 Answers

By default, no, mod_rewrite's internal redirects don't work across domains, unless both domains are hosted on the same server.

You could of course redirect requests to the other server:

 RewriteRule ^images/(.*) http://imagesite.com/images/$1 [R]

but this may not be what you want (the browser's address bar will show the address of the image server).

You can, however, use the P flag to have mod_proxy make a proxy request. The example given in the manual is exactly what you'd like to achieve:

RewriteRule (.*)\.(jpg|gif|png)$ http://images.example.com/$1.$2 [P]

mod_proxy is very cool, but it's probably more economical and easier to just handle this with a server-side language: internally redirect requests to a script which fetches the remote image and outputs it - see this question for solutions for this.

like image 133
SáT Avatar answered Apr 13 '26 08:04

SáT