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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With