将所有内容重写为 index.php?

Rewrite everything to index.php?

这是一个简短的问题。如何更改 .htaccess 文件以重写所有内容以将其重定向到 index.php 文件?

当我删除 RewriteCond 行时,我会得到一个 505 Internal Server Error

这是我的 .htaccess 文件:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

您可以使用这条规则:

RewriteEngine on

RewriteCond %{REQUEST_URI} !\.(?:jpe?g|gif|bmp|png|ico|tiff|css|js)$ [NC]
RewriteRule !^index\.php$ index.php [L,NC]
  • RewriteCond 将跳过对 image/css/js 个文件的重写。
  • 否定表达式!^index\.php$表示匹配除index.php以外的任何内容。