I am attempting to create automatic subdomains using Apache 2 (running on a Ubuntu box)
I have used the VirtualDocumentRoot
directive to do the initial declaring of the document root, with the following in my virtual host file:
<VirtualHost *:80>
VirtualDocumentRoot /var/www/dev/branches/%1/public/
ServerAlias *.dev.example.com
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This works well for the first part, so a request to foo.dev.example.com
has a document root of /var/www/dev/branches/foo/public
, which is great.
The problem
Alas, the *.htaccess
file I have in the public folders doesn't seem to be working.
All requests should be sent through index.php in the public folder, as the .htaccess
file shows:
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
# redirects requests to index.php where no file or directory exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php
</IfModule>
A request to foo.dev.example.com
works, but a request to foo.dev.example.com/subdir
fails.
Help!
Edit:
I have an error log that shows this is a mod_rewrite problem:
[Thu Aug 04 14:05:45 2011] [error] [client 217.206.134.99] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Thu Aug 04 14:05:45 2011] [debug] core.c(3063): [client 217.206.134.99] r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /user/login
[Thu Aug 04 14:05:45 2011] [debug] mod_deflate.c(615): [client 217.206.134.99] Zlib: Compressed 630 to 389 : URL /var/www/dev/branches/amy/public/index.php
You can get this more or less working using these rules:
The only problem with this is, if there is a default index page in one of the directories, it can only be accessed directly, http://domain.tld/subdir/index.php Just using http://domain.tld/subdir/ would rewrite it to http://domain.tld/index.php