有以下重写规则
RewriteEngine On
RewriteCond %{REQUEST_URI} !/(js|css|images)/
RewriteRule section/([0-9a-zA-Z_-]+)$ /index.php?controller=section&method=index¶m=$1
RewriteRule category/([0-9a-zA-Z_-]+)$ /index.php?controller=category&method=products¶m=$1
RewriteRule ([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)/(.*)$ /index.php?controller=$1&method=$2¶m=$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,它没有。它与部分和类别规则有关,因为当我删除这两行时,一切正常
答案 0 :(得分:1)
您需要为每个规则重复条件,该条件仅适用于紧随其后的规则。删除2节和类别规则时它的工作原因是因为条件正在应用于第3个规则(这就是搞乱你的问题)。您需要为每个规则重复该条件:
RewriteEngine On
RewriteCond %{REQUEST_URI} !/(js|css|images)/
RewriteRule section/([0-9a-zA-Z_-]+)$ /index.php?controller=section&method=index¶m=$1
RewriteCond %{REQUEST_URI} !/(js|css|images)/
RewriteRule category/([0-9a-zA-Z_-]+)$ /index.php?controller=category&method=products¶m=$1
RewriteCond %{REQUEST_URI} !/(js|css|images)/
RewriteRule ([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)/(.*)$ /index.php?controller=$1&method=$2¶m=$3
RewriteCond %{REQUEST_URI} !/(js|css|images)/
RewriteRule ([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)$ /index.php?controller=$1&method=$2