Mod rewrite 重写逻辑,有更好的方法吗?

Mod rewrite 重写逻辑,有更好的方法吗?,mod-rewrite,apache2,vhosts,Mod Rewrite,Apache2,Vhosts,我很好奇,有没有更有效的方法来做以下事情?现在它工作得很好,只是看起来太过分了 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !\.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf)$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l Rewri

我很好奇,有没有更有效的方法来做以下事情?现在它工作得很好,只是看起来太过分了

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !\.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{HTTP_HOST} !^www\.clientcollabhq\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.clientcollabhq\.com$ [NC]
RewriteRule ^(.+)$ /index.php?subdomain=%2&kohana_uri=$1 [PT,L,QSA]

RewriteCond %{REQUEST_FILENAME} !\.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ /index.php?kohana_uri=$1 [PT,L,QSA]
问候,,
Andrew

您可以使用倒置形式的通用条件作为中断/跳过规则的条件:

# stop processing if one of these conditions are fulfilled
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]

RewriteCond %{HTTP_HOST} !^www\.clientcollabhq\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.clientcollabhq\.com$ [NC]
RewriteRule ^(.+)$ /index.php?subdomain=%2&kohana_uri=$1 [PT,L,QSA]

RewriteRule ^(.+)$ /index.php?kohana_uri=$1 [PT,L,QSA]
现在,每一个符合这些条件之一的请求都将使这个规则被应用,从而结束重写过程