2010-07-27 79 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