vault-boy
vault-boy

Reputation: 523

rewriting rules, excluding condition

Have a following rewriting rule

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

Now, when I call for /js/jquery.js, I get the file fine. But if the file is one folder level deeper, eg. /js/fancybox/jquery.fancybox-1.3.4.pack.js, it doesn't. It has something to do with section and category rules as everything works fine when I remove those two lines

Upvotes: 0

Views: 85

Answers (1)

Jon Lin
Jon Lin

Reputation: 143856

You need to repeat the condition for each rule, the condition only applies to the immediately following rule. The reason why it works when you remove the 2 section and category rules is because the condition is being applied to the 3rd rule (which is what's messing you up). You need the condition repeated for each rule:

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

Upvotes: 1

Related Questions