.htaccess <filesMatch> only if host name matches?

戏子无情 提交于 2020-03-24 08:03:07

问题


I just setted up a local environament with same code that I had in production environament into a vagrant virtual machine with ubuntu32,

The thing is that I got Internal Server Error with all my rules in the .htaccess file

So I started removing separated blocks of code and this was the trouble:

# 1 weeks
<FilesMatch "\.(js|css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 1 weeks
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 1 MIN
<FilesMatch "\.(html|htm|php)$">
Header set Cache-Control "max-age=60, private, proxy-revalidate"
</FilesMatch>

The thing is that I would like to use the exact same code for all environaments, is there a way I can only include that block of <filesMatch> only if not in localhost?

I found this answer but it just refers to a page, not the host name.


回答1:


You can probably do:

SetEnvIf Host ^ NON_LOCAL
SetEnvIf Host localhost !NON_LOCAL

<FilesMatch "\.(js|css)$">
Header set Cache-Control "max-age=604800, public" env=NON_LOCAL
</FilesMatch>

# 1 weeks
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public" env=NON_LOCAL
</FilesMatch>

# 1 MIN
<FilesMatch "\.(html|htm|php)$">
Header set Cache-Control "max-age=60, private, proxy-revalidate" env=NON_LOCAL
</FilesMatch>


来源:https://stackoverflow.com/questions/22422954/htaccess-filesmatch-only-if-host-name-matches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!