Volomike
Volomike

Reputation: 24886

Stopping Apache Rewrite Rules

Currently I'm doing something like this in my .htaccess:

RewriteRule ^assets/(.*)$   application/views/assets/$1

RewriteCond %{REQUEST_FILENAME} !/application/views/assets/.*

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

However, is there a way I can remove that first RewriteCond, such as use a [L] or [S=4] somewhere so that once that first RewriteRule (the one for assets) applies, we move on and don't apply further rules?

(BTW, this is an .htaccess file used for the KohanaPHP framework.)

Upvotes: 1

Views: 741

Answers (1)

anubhava
anubhava

Reputation: 785266

Have your rule like this:

RewriteEngine on
Options +FollowSymlinks -MultiViews

RewriteCond %{REQUEST_URI} ^/assets
RewriteRule . - [S=10]

RewriteRule ^assets/(.*)$ /application/views/assets/$1 [L]

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* /index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* /index.php/$0 [PT]

Notice S=10 at the top to skip next 10 rule if stat of REQUEST_URI matches /assets. And because of that rule I could safely removed negative rule condition RewriteCond %{REQUEST_URI} !^/application/views/assets/

To read more about option flags in mod_rewrite please see this doc: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriteflags

Upvotes: 1

Related Questions