VirtualDocumentRoot Domains and Subdomains

Is it possible to have VirtualDocumentRoot for normal domains and subdomains?

http://www.example.com/ or http://example.com

Uses:

/var/www/example.com/

And

http://*.example.com

Uses

/var/www/example.com/subdomains/*

What i have so far: Pastebin - VirtualDocumentRoot Domains and Subdomains

The normal domain works except the subdomains, appearently it always redirects to the normal domain. This information i used is coming from Stackoverflow - Apache-multiple-virtualdocumentroot

# get the server name from the Host: header
UseCanonicalName Off

# this log format can be split per-virtual-host based on the first field
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName domain.com
    ServerAlias www.domain.com domain.com
    VirtualDocumentRoot /var/www/%-2.0.%-1/web

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel debug
    ErrorLog /var/log/apache2/vhosts-error.log
    CustomLog /var/log/apache2/vhosts-access.log combined

    ServerSignature On
</VirtualHost>
<VirtualHost *:80>
    ServerName domain.com
    ServerAlias *.domain.com
    VirtualDocumentRoot /var/www/%-2.0.%-1/subdomains/%-3
</VirtualHost>

Update v2 [worked for me, just ignore the subdomains till now..]

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com example.com
    Options Indexes FollowSymLinks

    VirtualDocumentRoot /var/www/%-2_%-1/web/

    <Directory />
            AllowOverride none
    </Directory>

    <Directory "/var/www/*/web/">
        RewriteEngine on
        RewriteBase /
        # If a directory or a file exists, use it directly
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        # Otherwise forward it to index.php
        RewriteRule . index.php [L]


        <Files sitemap.xml>
            RewriteEngine Off
        </Files>
    </Directory>


        LogLevel debug
        ErrorLog /var/log/apache2/vhosts-error.log
        CustomLog /var/log/apache2/vhosts-access.log combined
</VirtualHost>

Answers


You can specify a folder on your server for each domain and/or sub-domain :) See http://httpd.apache.org/docs/current/vhosts/examples.html for samples.

If you get problems with the subdomain or domain please check your DNS record to see if subdomains are enabled for your domain. Else add a 'A' record with your subdomain or an alias like *.doamin.com Basiccly what this does, is pointing the subdomain to your server IP address.

Check this article for an easy guide to DNS : https://support.google.com/a/answer/48090?hl=en


Need Your Help

How can I organize my code to optionally provide a backing view for my logic layer?

ios architecture custom-component

I'm a bit sceptic wether this belongs to stackoverflow or not, please let me know if I should post to codereview or programmers instead.

jquery unbind method

jquery unbind

if my html looks like this: