Subdomain Rewrite Logic
I have the following Rewrite Logic, and it's working to redirect the subdomain, partially. If I visit the URL http://subdomain.clientcollabhq.com/some/path it redirects properly, but if I visit http://subdomain.clientcollabhq.com/ it skips the RewriteCond blocks for the subdomain and falls into the fallback RewriteRule. Any idea what's going on?
#
# ClientCollabHQ
#
<VirtualHost *:80>
ServerAdm开发者_StackOverflow社区in webmaster@dummy-host.localhost
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>
Regards,
AndrewI'm not sure which section you meant by "fallback", but for the URL http://subdomain.clientcollabhq.com/, one of the following conditions will be true (I'm fairly certain it's the -d
, because the DirectoryIndex
shouldn't have been applied yet I think):
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
The reason for this is that your subdomain points to your site root, which happens to be a real resource. Since the conditions are true, no rewrite is done, and you should end up at index.php
with no arguments. You could work around this by adding another condition to the first set, which would make sure that something other than the root is requested before short-circuiting the later rules.
For instance:
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]
精彩评论