是否有可能设置头conditionaly? [英] Is it possible to set headers conditionaly?

查看:198
本文介绍了是否有可能设置头conditionaly?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想htaccess的执行以下code仅当HTTP_REFERER是从谷歌(.COM / .RU / .co.uk /.co.in/等)。这可能吗?

 < filesMatch&GT(JPG | JPEG | | PNG GIF)$。
FileETag无
< ifModule mod_headers.c>
头取消设置的ETag
头设置缓存控制最大年龄= 0,无缓存,无店铺,必重新验证
头设置语用无缓存
头中设置过期周三,1984年01月11日05:00:00 GMT
< / ifModule>
< / FilesMatch>


解决方案

好吧,我想通了,你可以使用mod_rewrite使设置头一个不同的方式,它更容易:

 的RewriteCond%{HTTP_USER_AGENT}(Googlebot的| bingbot | Baiduspider)![NC]
的RewriteCond%{HTTP_REFERER}谷歌[NC]
。重写规则^ * $ - [ENV = LONGCACHE:真]
头设置缓存控制最大年龄= 0,无缓存,无店铺,必重新验证ENV = LONGCACHE
头设置语用无缓存ENV = LONGCACHE
头中设置过期周三,1984年01月11日05:00:00 GMTENV = LONGCACHE

I would like to 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>

解决方案

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 

这篇关于是否有可能设置头conditionaly?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆