2011-04-19 227 views
1

目前我正在做這樣的事情在我的.htaccess:停止Apache重寫規則

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] 

但是,是有辦法,我可以刪除第一的RewriteCond,如使用[L]或[ S = 4],這樣,一旦第一個RewriteRule(資產的一個)適用,我們繼續前進,不再應用更多規則?

(順便說一句,這是用於KohanaPHP框架.htaccess文件。)

回答

1

讓你的規則是這樣的:

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] 

通知S=10頂部跳到下一個10規則,如果統計的REQUEST_URI匹配/資產。而由於該規則的,我可以安全地刪除負面規則條件RewriteCond %{REQUEST_URI} !^/application/views/assets/

要mod_rewrite的閱讀更多關於選項標誌請參閱此文檔:http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriteflags

+0

哇,似乎更多的工作不僅僅是離開的RewriteCond線。然而,你向我解釋了一些事情。你是贏家。 – Volomike 2011-04-21 01:08:22