Apache 的 AllowOverride All 并不像你想象的那样
我只需要为一个学校项目设置一个 Apache 服务器。 因为我喜欢使用 .htaccess
文件来设置重写规则并摆弄一些其他选项,所以除了标准批处理之外还必须加载一些额外的模块。
使用 phpinfo()
可以轻松检查当前加载了哪些模块,如这篇关于在 Apache 中启用 mod_rewrite 的文章中所述。
激活 Apache 模块很简单:只需打开 Apache 安装 /conf/ 文件夹中的 httpd.conf 文件,然后取消注释(或添加)相应的行。 注释行始终以井号 (
#
) 开头。
基本上,要加载 mod_negotiation
(用于多视图)和 mod_rewrite
(用于重写规则),我们只需将以下行添加到 httpd.conf:
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule rewrite_module modules/mod_rewrite.so
到目前为止,一切都很好。 Apache 被指示加载额外的模块; 我们现在应该能够使用 MultiViews
并通过在 .htaccess
文件中定义它们来重写规则。
然而,当我尝试使用 Options +MultiViews
时,我得到的只是那些臭名昭著的“500 Internal Server Error”页面之一。
错误日志在 .htaccess: Option MultiViews not allowed here 的行中说了一些东西。
在这种情况下,谷歌并没有真正提供帮助。 起初,我只能找到有同样问题的人。 在我真正开始浏览旧的 #apache IRC
日志之前,我找不到任何解决方案。
事实证明,Apache 在 httpd.conf 中有一个默认设置,它指定了可以被写入 .htaccess 文件的内容覆盖的设置:AllowOverride
。 我们的 httpd.conf 可能包含如下内容:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
与我们的想法相反,All
参数并不真正意味着“**[允许覆盖]所有选项** ”,因为它不包括 MultiViews
选项! 这里的关键是使用AllowOverride Options=All,MultiViews
。 与所有其他指令分组一起,这是我们需要的代码:
<Directory />
Options FollowSymLinks
AllowOverride AuthConfig FileInfo Indexes Limit Options=All,MultiViews
Order deny,allow
Deny from all
</Directory>
相关文章
Issues to note when installing Apache on Linux
发布时间:2025/04/08 浏览次数:78 分类:OPERATING SYSTEM
-
As the most commonly used web server, Apache can be used in most computer operating systems. As a free and open source Unix-like operating system, Linux and Apache are a golden pair. This article will introduce the installation and use of A
Apache2.4 installation and precautions under Windows7
发布时间:2025/04/08 浏览次数:125 分类:OPERATING SYSTEM
-
To install apache2.4 in Windows 7, we first need to download the apache2.4 installation program. Here we download the software from the apache official website http://httpd.apache.org/download.cgi . First, let's see how to download apache2.
Apache2.4+PHP5.6 environment configuration under Windows7
发布时间:2025/04/07 浏览次数:103 分类:OPERATING SYSTEM
-
I upgraded my Windows 7 32-bit operating system to a 64-bit operating system, and the previous PHP environment also needed to be reconfigured. Previously, I used apache2.2 and php5.3. Since I upgraded the operating system, I also upgraded t
Configuring Apache Web Server on Ubuntu and Debian
发布时间:2025/04/05 浏览次数:176 分类:OPERATING SYSTEM
-
This article shows you how to install Apache web server on Ubuntu and Debian, set it up, and access the access logs. Apache Web Server in Ubuntu and Debian Apache HTTP Server is a free and open source web server that is very popular. More t
Apache's AllowOverride All doesn't do what you think
发布时间:2025/03/17 浏览次数:86 分类:NETWORK
-
I just had to set up an Apache server for a school project. Since I like to use .htaccess files to set rewrite rules and fiddle with some other options, I had to load some extra modules in addition to the standard batch processing. Using phpin
解决 Java 异常 Unable to Instantiate org.apache.hadoop.hive.ql.metadata.Sessi
发布时间:2023/07/14 浏览次数:257 分类:Java
-
本篇文章介绍如何解决 java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient。Apache Hive 是一款开源数据仓库软件,用于读取、管理和写入存储在 Hadoop 文件中的大
解决 Java 错误 Java.Lang.NoClassDefFoundError: Org/Apache/Commons/Logging/Log
发布时间:2023/07/11 浏览次数:169 分类:Java
-
本篇文章介绍了 Java 中的 java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory 错误。解决java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
在 Apache2 中启用 PHP
发布时间:2023/03/27 浏览次数:208 分类:PHP
-
本文将教你如何使用 a2enmod、LoadModule 和符号链接在 Apache2 中启用 PHP。如果你遇到有关 PHP 的模块错误,我们将教你如何通过 apt-get 修复它。
在 Ubuntu 和 Debian 上配置 Apache Web 服务器
发布时间:2023/03/17 浏览次数:191 分类:操作系统
-
本教程展示了在 Ubuntu 和 Debian 上安装和设置 apache 网络服务器以及使用访问日志。