【问题标题】:Rewrite Logic, is there a better way to do this?重写逻辑,有没有更好的方法来做到这一点?
【发布时间】:2011-03-10 09:19:38
【问题描述】:

我很好奇,有没有更有效的方法来执行以下操作?现在它工作得很好,只是看起来有点矫枉过正......

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]

问候, 安德鲁

【问题讨论】:

    标签: mod-rewrite apache2 vhosts


    【解决方案1】:

    您可以使用反转形式的常见条件作为中断/跳过规则的条件:

    # 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]
    

    现在每个符合这些条件之一的请求都会应用此规则,从而结束重写过程。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-08
      • 1970-01-01
      相关资源
      最近更新 更多