apache - 用于无条件附加“index.php”的 Apache2 RewriteRule
问题描述
我在 Debian 10 上使用 Apache 2.4.38 和 PHP v7.3 运行网站“example.com”。
在主 apache2 配置文件 /etc/apache2/apache2.conf 我有一个 RewriteRule 自动将 http 转换为 https。这条规则完美运行。摘抄:
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
</IfModule>
对于特定的虚拟主机文件(内容就在下面)
<VirtualHost *:443>
<Directory /var/www/html/abc>
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
Options FollowSymLinks Indexes MultiViews
AllowOverride None
Require all granted
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} !^(/index\.php|/img|/js|/css|robots\.txt|/favicon\.ico)
RewriteRule ^(.*)$ %{HTTP_HOST}/$1/index.php [R=301,L]
</IfModule>
</Directory>
</VirtualHost>
调用任何一个
- example.com/abc
- http://example.com/abc
- https://example.com/abc
应该导致https://example.com/abc/index.php(即字符串“index.php”应该无条件地附加到完全限定的字符串“https://example.com/abc”</p>
不幸的是我没有成功。有人可以指出我正确的解决方案吗?
您是否建议将第二个 RewriteRule(我正在寻找工作)也放入文件 /etc/apache2/apache2.conf 中,还是应该将其放入 /var/www.html/abc 的虚拟主机文件中?
请注意:我不希望将第二个 RewriteRule 放入 .htaccess 文件中。
解决方案
推荐阅读
- sql - 如何使用 PostgreSQL 从列中仅获取部分单词并删除其前后的所有内容
- powershell - 如何在 api post 命令中传递非英语字符
- ios - 尝试在 Mac M1 上使用 Firebase 运行 Flutter 应用程序失败
- javascript - 禁用 q-item 上的突出显示(Quasar Framework)
- opencv - Leadtools 位图到 OpenCV Mat 并返回
- python-3.x - tkinter 没有 x11 XQuartz
- java - Java 未捕获从“AWT-EventQueue-0”java.lang.IndexOutOfBoundsException 引发的异常:
- listview - Win32 ListView typeahead 搜索的算法
- javascript - raw-loader 和 vue3 - 未找到依赖项
- c - 优雅地将 m4 宏处理器添加到 gcc 编译链中?