0

I would like to proxy images calls from external domains, for example that url:

https://example.com/proxy/http://externaldomain.com/image.jpg

Would respond the image (not a redirection).

  • so far I implemented it at my application level. It works, but if I can scope it outside of my app and let the webserver deal with that, it would be better i think – thesearentthedroids Jan 10 '17 at 10:54

1 Answers1

0

Try this rule for .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.jpg -f [OR]
RewriteCond %{REQUEST_FILENAME}.png -f
RewriteRule ^(.*)$ http://external.com/$1 [P]

OR

In httpd.conf:

ProxyPreserveHost off
ProxyPassMatch ^/(.*\.(jpg|png))$ http://external.com/$1

Although I didn't checked both of the rules for now but please ensure that these two lines are uncommented in httpd.conf.

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
  • The regexp in `ProxyPassMatch` is wrong, since the `|` effectively splits the expression in half, so it will proxy the `.*\.jpg` or the `png` pattern (the latter being just three characters). Use the `^/(.*\.(jpg|png))` pattern instead. Also if name-based virtual hosts are used on the backend, the `ProxyPreserveHost` must be set to `Off`. – Lacek Jan 10 '17 at 13:15
  • Thanks, I just wanted to make it clear that the external domain must be a variable, but the rule on .jpg and png is clever – thesearentthedroids Jan 10 '17 at 17:03