问题原文
原帖链接 · twharmon · CC BY-SA 3.0
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType application/javascript "access 1 week"
ExpiresByType text/css "access 1 week"
</IfModule>
I use a lot of these in my .htaccess files to set caching, deflate, Accept-encoding headers and stuff. I have noticed that if I delete the open and close tags, everything keeps working. What do these do, and is it safe to delete them, as long as everything seems to be working right?
已采纳解答
原帖链接 · Unbeliever · CC BY-SA 3.0
<IfModule> is simply a directive that tests the condition "is the named module loaded by apache httpd" (in your example mod_expires). It allows people to produce conditional based configuration for different installations where certain modules may be present or not.
Best practise is not to use it unless necessary. Ideally, you should know which modules your web server loads and thus which configuration directives are available.
You can always check the modules you web server is loading using apachectl -M and apachectl configtest before restarting your web server should reveal any directives that you have used without loading the relevant module.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
