我已经安装了新的Apache 2.2在我的Vista机器上,一切正常,除了mod重写。
我没有注释
LoadModule rewrite_module modules/mod_rewrite.s
但是我的重写规则都不起作用,即使是简单的规则也是如此
RewriteRule not_found %{DOCUMENT_ROOT}/index.php?page=404
我正在使用的所有规则正在处理我的托管,所以他们应该没问题,所以我的问题是,有没有在Apache配置隐藏的东西?
对于我的情况,我有
RewriteEngine On
在我的.htaccess,随着模块被加载,并没有工作。
我的问题的解决方案是编辑我的虚拟主机条目进入
AllowOverride all
在该<Directory>网站的部分。
为了使用mod_rewrite您可以在终端中键入以下命令:
a2enmod rewrite
之后重新启动apache2
/etc/init.d/apache2 restart
要么
service apache2 restart
或按照新的统一的系统控制方式
systemctl restart apache2
那么,如果你愿意,你可以使用下面的.htaccess文件。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
上面的.htaccess文件(如果放在你DocumentRoot的index.php文件中)将把所有流量重定向到文件中,DocumentRoot除非文件存在。
所以,假设你有以下的目录结构,而httpdocs是 DocumentRoot
httpdocs/
.htaccess
index.php
images/
hello.png
js/
jquery.js
css/
style.css
includes/
app/
app.php
httpdocs中存在的任何文件都将使用.htaccess上面显示的方式提供给请求者,不过,其他所有内容都将被重定向到httpdocs/index.php。您的应用程序文件includes/app将不可访问。