使用RewriteRule排除文件名

时间:2013-08-07 12:22:46

标签: apache .htaccess

我想将所有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]

1 个答案:

答案 0 :(得分: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]