在.htaccess中重定向到index.php时出错


Error when redirecting to index.php in .htaccess

我正在通过.htaccess将我的域重定向到public_html文件夹中的子文件夹,如下所示:

DirectoryIndex index.php
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ 
RewriteCond %{REQUEST_URI} !^/mydomain.com/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /mydomain.com/$1 
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ 
RewriteRule ^(/)?$ mydomain.com/php [L]

在编写mydomain.com/index.php时,一切都很好,但如果我去掉index.php,只写mydomain.co,我会得到404错误?!?

我错过了什么?

如有任何帮助,我们将不胜感激:-)

^(.*)$模式更改为^(.+)$

或者,切换规则的顺序。

您是否尝试过从中删除尾部斜线

RewriteCond %{REQUEST_URI} !^/mydomain.com/

使其成为

RewriteCond %{REQUEST_URI} !^/mydomain.com