所以我有以下重写规则:
RewriteRule ([^/]*)/([^/]*)/([^/]*)$ /index.php?grandparent=$1&parent=$2&page=$3
RewriteRule ([^/]*)/([^/]*)$ /index.php?&parent=$1&page=$2
RewriteRule ([^/]*)$ /index.php?page=$1
但我需要将其传递给某些子域的索引页面,所以在此之前我有以下重写条件:
RewriteCond %{REQUEST_URI} !^/css/.*$
RewriteCond %{REQUEST_URI} !^/js/.*$
RewriteCond %{REQUEST_URI} !^/admin/.*$
因此,当查找这些目录中的任何文件(包括可能位于这些目录的子目录中的文件)时,规则将不适用。然而,他们仍然被重写为index.php
。
如何为这些目录设置例外?
答案 0 :(得分:7)
你的RewriteCond应该是这样的:
RewriteCond %{REQUEST_URI} !^/(admin|js|css)/ [NC]
此外,您必须在所有RewriteRule行中使用L
和QSA
标记,如下所示:
# skip these paths for redirection
RewriteCond %{REQUEST_URI} !^/(admin|js|css)/ [NC]
RewriteRule ^ - [L]
RewriteRule ([^/]*)/([^/]*)/([^/]*)/?$ index.php?grandparent=$1&parent=$2&page=$3 [L,QSA]
RewriteRule ([^/]*)/([^/]*)/?$ index.php?&parent=$1&page=$2 [L,QSA]
RewriteRule ([^/]*)/?$ index.php?page=$1 [L,QSA]
答案 1 :(得分:4)
试试这个:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(admin|css|js)/
RewriteRule . - [S=3] #skip the next 3 rules if the RewriteCond match
RewriteRule ([^/]*)/?$ index.php?page=$1 [NC,L,QSA]
RewriteRule ([^/]*)/([^/]*)/?$ index.php?&parent=$1&page=$2 [NC,L,QSA]
RewriteRule ([^/]*)/([^/]*)/([^/]*)/?$ index.php?grandparent=$1&parent=$2&page=$3 [NC,L,QSA]