2010-07-27 75 views
0

我有以下重寫邏輯,它的工作部分重定向子域。如果我訪問URL http://subdomain.clientcollabhq.com/some/path它會正確重定向,但如果我訪問http://subdomain.clientcollabhq.com/,它將跳過子域的RewriteCond塊並落入回退RewriteRule。任何想法發生了什麼?子域重寫邏輯

# 
# ClientCollabHQ 
# 
<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName clientcollabhq.com 
    ServerAlias *.clientcollabhq.com 

    DirectoryIndex index.php 
    DocumentRoot "D:/wamp/www/dropbox/My Dropbox/ClientCollabHQ/www/html" 
    ErrorLog "D:/wamp/www/dropbox/My Dropbox/ClientCollabHQ/www/logs/error.log" 

    RewriteEngine On 

    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] 
</VirtualHost> 

問候,
安德魯

回答

1

我不知道你所說的「回退」意指部分,但對於URL http://subdomain.clientcollabhq.com/,符合下列條件之一將是真實的(我相當肯定它的-d,因爲DirectoryIndex不應該被應用於但我認爲):

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d [OR] 

這樣做的原因是,你的子域名指向你網站的根,這恰好是一個真正的資源。由於條件屬實,因此不會進行重寫,並且最終應該在index.php處沒有參數。您可以通過向第一組添加另一個條件來解決此問題,這可以確保在短路規則之前請求除根之外的其他內容。

例如:

RewriteCond %{REQUEST_URI} ^/.+$ 
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] 
+0

工作究竟應該如何現在。謝謝! – 2010-07-27 15:17:09