apache.htaccesscache-controlmod-headers

Is it possible to set headers conditionally?


I would like .htaccess to perform the following code ONLY if http_referer is from google (.com/ .ru/ .co.uk /.co.in/ etc.). Is this possible?

<filesMatch ".(jpg|jpeg|png|gif)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</FilesMatch>

Solution

  • Well I figured out you can set headers a different way using mod_rewrite making it much easier:

    RewriteCond %{HTTP_USER_AGENT} !(googlebot|bingbot|Baiduspider) [NC]  
    RewriteCond %{HTTP_REFERER} google [NC]  
    RewriteRule ^.*$ - [ENV=LONGCACHE:true]
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" env=LONGCACHE
    Header set Pragma "no-cache" env=LONGCACHE
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT" env=LONGCACHE