0

有以下重写规则

RewriteEngine On
RewriteCond %{REQUEST_URI} !/(js|css|images)/

RewriteRule section/([0-9a-zA-Z_-]+)$ /index.php?controller=section&method=index&param=$1
RewriteRule category/([0-9a-zA-Z_-]+)$ /index.php?controller=category&method=products&param=$1
RewriteRule ([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)/(.*)$ /index.php?controller=$1&method=$2&param=$3
RewriteRule ([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)$ /index.php?controller=$1&method=$2

现在,当我调用 /js/jquery.js 时,我得到了文件。但是,如果文件是更深一层的文件夹,例如。/js/fancybox/jquery.fancybox-1.3.4.pack.js,它没有。它与部分和类别规则有关,因为当我删除这两行时一切正常

4

1 回答 1

1

您需要为每个规则重复条件,该条件仅适用于紧随其后的规则。当您删除 2 部分和类别规则时它起作用的原因是因为条件被应用于第 3 条规则(这让您感到困惑)。您需要为每个规则重复条件:

RewriteEngine On

RewriteCond %{REQUEST_URI} !/(js|css|images)/
RewriteRule section/([0-9a-zA-Z_-]+)$ /index.php?controller=section&method=index&param=$1

RewriteCond %{REQUEST_URI} !/(js|css|images)/
RewriteRule category/([0-9a-zA-Z_-]+)$ /index.php?controller=category&method=products&param=$1

RewriteCond %{REQUEST_URI} !/(js|css|images)/
RewriteRule ([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)/(.*)$ /index.php?controller=$1&method=$2&param=$3

RewriteCond %{REQUEST_URI} !/(js|css|images)/
RewriteRule ([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)$ /index.php?controller=$1&method=$2
于 2012-08-29T12:06:15.123 回答