apache - mod_rewrite 已经启用但仍然得到 404

标签 apache .htaccess mod-rewrite url-rewriting

我正在构建一个 URL 友好的系统。主机是本地机器,Ubuntu 15.10。

该软件正在运行,但我犯了一个错误并删除了 apache2 目录。所以我用sudo apt-get purge apache2 php5 mysql-server清除了apache,然后我重新安装了所有内容:sudo apt-get install apache2 php5 mysql-server

重新安装后,我测试了一个公共(public)站点并且服务器已打开。然后,最后,我再次启用了 mod_rewrite:sudo a2enmod rewrite。并重新启动 apache2:sudo systemctl restart apache2。所以,一切似乎都就位,但是当我尝试我的友好 url 系统(之前可以正常工作)时,我只是收到 404 错误。

有人可以帮助我吗?

.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

请注意,这个 .htaccess 与之前的工作相同,我没有对源代码进行任何更改。

最佳答案

检查 AllowOverrideVirtualHost(然后是 httpd.conf)配置文件指令。

将其设置为允许 .htaccess 文件内的所有声明:

AllowOverride All

关于apache - mod_rewrite 已经启用但仍然得到 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35329008/

相关文章:

wordpress - 在子目录中设置 CakePHP; WordPress 安装在根目录下

javascript - .htaccess RewriteRule 在 javascript 中添加为非斜杠的多个参数

apache - 这个 RewriteCond 中的 $1 参数有什么作用?

php - 301 重定向正在附加 ?_url

python - 异常值 :attempt to write a readonly database Centos 8 Apache webserver Python 3. 6

java - Apache org.apache.commons.graph

.htaccess 将 "/"重定向到非 "/"是 500 内部服务器错误

html - 如何使用 Apache 记录页面请求?

php - 如何让搜索引擎索引动态生成的页面

apache - URL 重写和文件夹