大网数据广告活动
服务器运维问答

What does <IfModule> do in .htaccess?

· 52CE 我爱测

<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…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-10-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。