Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

You can get this more or less working using these rules:

Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L]
</IfModule>

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

share|improve this answer
    
Thanks derchris, but this gave the exact same redirection errors in Apache. –  Kevin Sedgley Aug 4 '11 at 14:14
    
I tested it on mine, and worked –  derchris Aug 4 '11 at 17:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.