RewriteRule和DirectoryIndex之间的冲突


Conflict between RewriteRule and DirectoryIndex

我看到了这个问题,但没有帮助
我正在尝试根据正在运行的活动项目设置一个回退文件
如果项目根没有main.php,那么它应该回退到index.php
我已经使用以下代码做到了这一点:

DirectoryIndex main.php index.php index.html

但我的问题是,我找不到一种方法来为RewriteRule设置相同的规则。我正在尝试这样的东西,但它给了我500个错误:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . main.php index.php

如何在RewriteRule中设置回退,使其与DirectoryIndex一样工作?

此规则应该有效:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^main'.php$ index.php [L,NC]

您尝试的规则在规则模式中有一个额外的点。