Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache .htaccess无效且不';发送过期报头_Apache_.htaccess - Fatal编程技术网

Apache .htaccess无效且不';发送过期报头

Apache .htaccess无效且不';发送过期报头,apache,.htaccess,Apache,.htaccess,我将.htaccess文件添加到网站根文件夹/var/www/html 看起来像这样 ## EXPIRES CACHING ## <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/jpg "access 1 year" ExpiresByType image/jpeg "access 1 year" ExpiresByType image/gif "access 1 year" ExpiresByType im

我将
.htaccess
文件添加到网站根文件夹
/var/www/html
看起来像这样

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
/etc/apache2/apache2.conf
看起来是这样的

<VirtualHost *:80>
    <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
...
</VirtualHost *:80>
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

选项如下符号链接
不允许超限
要求全部拒绝
不允许超限
要求所有授权
选项索引跟随符号链接
允许超越所有
要求所有授权
我相当肯定
.htaccess
文件不起作用,因为当我向文件中添加随机字符(尝试将其打断并获得
500
HTTP响应)时,它根本不会影响网站。
这可能是什么原因造成的

过期信息由expires模块创建并发送。因此,
.htaccess
会正确检查此模块是否存在。如果未加载,则此处不执行任何操作

确保模块加载正确,当前最兼容的方法是使用
a2enmod

:~ $ a2enmod expires

由于.htaccess声明只有在加载mod_expires时才会执行任何操作:您确定加载了mod_expires吗
a2enmod mod_expires
可能会有帮助。这在@FlorianHeer是很有意义的,事实上这就是问题所在!我没有意识到我必须手动启动这个模块。如果你将此作为答复提交,我将接受。只需确保写下
a2enmod expires
而不是
a2enmod\u expires
谢谢。我总是忘记'mod_uu'对于
a2enmod
是不必要的,我几乎每次都会收到错误消息;-)