Search code examples
phpapache.htaccessheadermod-proxy

How can proxied image headers be modified on Apache?


We proxy images as licensed content and need to add max-age headers to the proxied images. Attempted modifying .htaccess, but it didn't work and suspect this is due to the proxied image folder not being an actual directory on the server.

First, the proxy is set up in apache2.conf:

# Image Proxy
ProxyPass /photo http://photo.licensor.com
ProxyPassReverse /photo http://photo.licensor.com

Made several attempts to modify .htaccess under the site's public_html directory. It appears that the condition to modify the max-age header for proxied images is never recognized by Apache since /photo is not a real directory.

I'd really like to target ONLY the proxied images using the /photo directory that isn't real.


Solution

  • You can't use a <location> container in an htaccess file. It's probably best to put this in your apache server config file next to your ProxyPass settings:

    <LocationMatch "/photo">
      # Image Proxy
      ProxyPass http://photo.licensor.com
      ProxyPassReverse http://photo.licensor.com
      Header unset Etag 
      Header set Cache-Control "max-age=86400, public" 
      Header unset Expires
    </LocationMatch>