.htaccess 无法在 Ubuntu 14.04(Apache 2.4.7)中加载

.htaccess 无法在 Ubuntu 14.04(Apache 2.4.7)中加载

.htaccess我正在尝试在 Ubuntu 14.04(Apache 2.4.7)中使用该文件。

以下是我的.htaccess样子

# 1 YEAR
<FilesMatch "\.(ico|svg|woff|eot|ttf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>

# 1 WEEK
<FilesMatch "\.(jpg|png|gif|css|js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

# Add correct content-type for fonts 
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType font/x-woff .woff
AddType image/svg+xml .svg

# Compress compressible fonts
AddOutputFilterByType DEFLATE font/ttf font/otf image/svg+xml

我使用启用了 mod_rewritea2enmod rewrite

然后我编辑/etc/apache2/apache2.conf如下

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

AccessFileName .htaccess

但是.htaccess文件仍然没有加载。如果我向.htaccess文件中添加乱码,一切仍然正常。.htaccess位于/var/www/

以下是输出apache2ctl -S

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost edmhunters.com (/etc/apache2/sites-enabled/edmhunters.com.conf:1)
                 alias www.edmhunters.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

我在这里错过了什么?

答案1

问题是,当我将.htaccess文件放入/var/www/时,我DocumentRoot的网站指向了另一个目录。将.htaccess文件移动到该文件夹​​解决了这个问题。

相关内容