I’m using a third party API that provides me with a bunch of images. I need to display about 20 to 30 images on a single page, but I don’t want anyone who is snooping at the source to know I’m using a third party service for these particular images. How would I go about masking these images so they look like they are coming from my domain name. I would preferably like to know how to do this with PHP or Apache.
P.S Is this bad practice or would I be better of downloading the images and saving them to the cloud?
Thanks
Edit: I took Gordons advice and tried the following and put the following code in my .htaccess, but It’s not working for some strange reason.
RewriteRule "^/?images(.*)" "https://img-inventory.supplier-domain.com/image/$1" [P]
ProxyPassReverse "/images/" "img-inventory.supplier-domain.com/image/"
The following is an example of the supplier URL
https://img-inventory.supplier-domain.com/image/upload/f_auto,q_auto:best,t_inv_small/hotel/i/155110/wpmeb5pjxdgse8kvfd87f.jpg
If anyone can kindly share what I’m doing wrong I would appreciate it.
2
Answers
You can mask them in php file:
and image.php like this:
It depends on where you storage URLs to images. But you need to prevent errors, if there is no image by the URL.
Obviously, the better practise is downloading images and show from your own storage.
If you are using Apache, you can do this without PHP by using either
mod_rewrite
ormod_proxy
.Quoting from http://httpd.apache.org/docs/2.4/rewrite/avoid.html#proxy
If you are using NGINX, you can use the
location
andproxy_pass
directives:See https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/ for details.
IMO, this is a better alternative than using a PHP proxy script because the webserver will handle caching for you. With a PHP script, you will need to handle this yourself.