我已经在我的Vista机器上安装了新的Apache 2.2,一切都很好,除了mod重写。

我已经激活

LoadModule rewrite_module modules/mod_rewrite.s

但我的重写规则都没用,即使是像这样简单的

RewriteRule not_found %{DOCUMENT_ROOT}/index.php?page=404

我使用的所有规则都在我的主机上工作,所以他们应该是好的,所以我的问题是,在apache配置中有任何隐藏的东西,可以阻止mod重写?


当前回答

如果没有以上工作尝试编辑/etc/apache2/sites-enabled/000-default

几乎在顶部你会发现

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

将AllowOverride None更改为AllowOverride All

这对我很有效

其他回答

使用以下命令

sudo a2enmod rewrite

并通过下面的命令重新启动apache

sudo service apache2 restart

显然有不止一种方法可以做到这一点,但我建议使用更标准的方法:

ErrorDocument 404 /index.php?page=404

如果你知道问题的根源,有很多方法可以解决这个问题。

问题1

首先,这可能是apache没有安装或启用mod_rewrite.c模块的问题。

因此,您必须按如下方式启用它

打开控制台,输入以下内容: Sudo a2enmod重写 重新启动apache服务器。 Service apache2 restart

问题2

除此之外,如果它不起作用,您还可以更改apache conf文件(apache2.conf, http.conf或000-default文件)的覆盖规则。 查找目录/var/www/ 将“Override None”更改为“Override All”

问题3

如果你得到一个错误说重写模块没有找到,那么可能是你的userdir模块 未启用。因此,您需要启用它。

在控制台中输入以下内容: Sudo a2enmod userdir 然后尝试启用重写模块,如果仍然未启用(如上所述)。

欲了解更多信息,请访问该网站:http://seventhsoulmountain.blogspot.com/2014/02/wordpress-permalink-ubuntu-problem-solutions.html

对我有用的(在ubuntu中):

sudo su
cd /etc/apache2/mods-enabled
ln ../mods-available/rewrite.load rewrite.load

另外,正如前面提到的,确保在/etc/apache2/sites-available/default的相关部分设置AllowOverride all

在Ubuntu中:

Run:

a2enmod rewrite

然后:

service apache2 restart

Mod_rewrite现在将被启用!