1

除非特定文件存在于根目录中,否则我想将所有 URI 传递到 index.php 中。当谈到排除 index.php 时,我有点难过,因为它当然不符合我最后的全部规则

Options +FollowSymLinks -Indexes
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} != "index/.php" // I'm not sure on the syntax here
RewriteRule ^(.*)$ $1.php [L]

RewriteRule ^([^/]*)(.*)$ index.php?category=$1&post=$2 [L,QSA]
4

1 回答 1

1

通过在最后一条规则中添加附加条件来解决

RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)(.*)$ index.php?category=$1&post=$2 [L,QSA]
于 2013-08-07T13:39:19.047 回答