.htaccess 重写规则无法正常工作

.htaccess rewrite rules do not work properly

当我打开 url 时,此 .htaccess 文件重写为 /admin/index.php: http://example.com/admin/

但是在 http://example.com/admin/accounts/ 上将请求重写为 /index.php(第一条规则)。

我的配置文件有什么问题?

AddDefaultCharset utf-8
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php [QSA,L]
RewriteRule ^admin/(.*)$ admin/index.php [QSA,L]
RewriteRule ^api/(.*)$ api.php [QSA,L]

您的最后两条规则被忽略,因为第一条规则通过匹配所有内容取代了它们 (.*)

因此,最后两条规则应移至 RewriteEngine on 下方。