apache - 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”。
有人知道我该如何解决吗?
米凯尔
解决方案
终于……好了!
我的 .htacess 文件被 Apache 忽略了,因为 AllowOverride 语句在我的“apache2.conf”中默认设置为“None”。
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
我通过“AllowOverride All”对其进行了更改,我重新启动了 Apache,我可以验证重写工作正常。
推荐阅读
- git - TFSVC 到 TFS-Git 与同一仓库中的子项目
- python - pd.date_range 在月底返回开始值,然后继续每月日期?
- c# - 使用 console.readline 保持进程存活时如何读取控制台输入?
- keras - 如何理解卷积模型
- javascript - 想要绕过仅包含网址的页面加载弹出窗口
- python - 修改 pivot_tables 中的 aggfunctions
- python - 如何解决用户和模型问题?
- php - 我想获得特定的搜索结果,而不是任何类似的词
- c# - 在 ASP.NET Core 中使用基于 ADFS 的身份验证来访问使用 Windows 身份验证的 SQL Server?
- python - np.loadtxt() 无法将 str 转换为 float 错误