首页 > 解决方案 > URL 重写问题 (Apache2 / Debian 10)

问题描述

我遇到了一个我无法解决的基本问题。

我在运行到 Docker 容器中的 Debian 10 机器上设置了 LAMP 服务器。

PHP 和服务 Apache 和 MySQL 是函数式的,但我遇到了 URL 重写的问题。它不运行,即使在我的网络服务器的基本入口点是:“http://localhost/”

如果我使用真实地址,它可以工作,但如果我将“虚拟”地址(例如“http://localhost/toto”)置于边缘,我会从 Apache 收到 404 错误。这是我放在基目录 "/var/www/html" 根目录下的 .htaccess 文件的内容:


Options +FollowSymlinks
RewriteEngine On
 
RewriteCond %{REQUEST_URI} !/index.php$
RewriteCond %{REQUEST_URI} !(.css|.js|.jpg|.jpeg|.png|.svg|.ttf|.woff|.woff2|.pdf|.zip|.mp4|.avi|.ogg)$
RewriteRule .* /index.php

在我的默认网站(/etc/apache2/sites-available/000-default.conf)的配置文件中,我有指令“DocumentRoot /var/www/html”。

如果我执行 phpinfo(),我会在加载模块中看到“mod_rewrite”。

有人知道我该如何解决吗?

米凯尔

标签: apacheurlrewriting

解决方案


终于……好了!

我的 .htacess 文件被 Apache 忽略了,因为 AllowOverride 语句在我的“apache2.conf”中默认设置为“None”。

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

我通过“AllowOverride All”对其进行了更改,我重新启动了 Apache,我可以验证重写工作正常。


推荐阅读