.htaccess未在Ubuntu 14.04(Apache 2.4.7)中加载 [英] .htaccess not being loaded in Ubuntu 14.04 (Apache 2.4.7)

查看:112
本文介绍了.htaccess未在Ubuntu 14.04(Apache 2.4.7)中加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use the .htaccess file in 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

我使用 a2enmod rewrite

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

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

AccessFileName .htaccess

但是 .htaccess 文件仍未加载。如果我在 .htaccess 文件中添加乱码,一切仍然可以正常进行。 .htaccess 位于 / var / www /

However the .htaccess file is still not being loaded. If I add gibberish to the .htaccess file everything still works fine. The .htaccess is located in /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

我在这里错过了什么?

这是 apachectl -t -D DUMP_MODULES <的输出/ code>

Here is the output of apachectl -t -D DUMP_MODULES

Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 expires_module (shared)
 filter_module (shared)
 headers_module (shared)
 mime_module (shared)
 mpm_event_module (shared)
 negotiation_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 status_module (shared)
 wsgi_module (shared)


推荐答案

问题是我将 .htaccess 文件放在 / var / www / 而我的网站的 DocumentRoot 指向另一个目录。将 .htaccess 文件移动到该文件夹​​即可解决此问题。

The isssue was that I was placing the .htaccess file in /var/www/ while my DocumentRoot for my website was pointing to a different directory. Moving the .htaccess file to that folder solved the issue.

这篇关于.htaccess未在Ubuntu 14.04(Apache 2.4.7)中加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆