.htaccess – 重写所有索引请求.php某些目录中的文件除外


.htaccess – rewrite all requests to index.php except for files in certain directories

实际上,我似乎找到了解决方案,但由于.htaccess和mod_rewrite总是令人困惑,因此我要求验证:

我想重写索引.php的所有流量,除了那些进入某些目录中现有文件的请求。这是正确的解决方案吗?...

RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !css/(.*)|js/(.*)|img/(.*)|media/(.*)
RewriteRule . index.php

我放弃了常用的

RewriteCond %{REQUEST_FILENAME} !-d

因为我不想有目录索引,并且没有我想要加载的索引.html或索引.php的子目录。

毕竟,这似乎是一个非常简单,安全和通用的设置,所以我问自己,为什么我以前从未见过。

你需要有这样的条件:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(css|js|img|media)/ [NC]
RewriteRule . index.php [L]