2

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>
Community
  • 1
  • 1
Martijn H.
  • 315
  • 4
  • 11

1 Answers1

0

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

  • With VirtualDocumentRoot I want to prevent duplication of the standard domain integration, see also my paste bin code. Im using A records. – Martijn H. Jan 31 '14 at 11:19
  • Have you tried debugging your host file? Use 'httpd -S' or 'apache2ctl -S' Or alternativ 'APACHE_RUN_USER=www-data APACHE_RUN_GROUP=www-data /usr/sbin/apache2 -S' You should add your own path depending on your server config. – Bjarke Brask Rubeksen Jan 31 '14 at 11:29
  • Found this thread for info on debugging : http://stackoverflow.com/questions/5474477/how-to-debug-an-apache-virtual-host-configuration – Bjarke Brask Rubeksen Jan 31 '14 at 11:32
  • *@*:/var/www$ sudo apache2 -t Config variable ${APACHE_LOCK_DIR} is not defined Config variable ${APACHE_PID_FILE} is not defined Config variable ${APACHE_RUN_USER} is not defined Config variable ${APACHE_RUN_GROUP} is not define Config variable ${APACHE_LOG_DIR} is not defined Config variable ${APACHE_LOG_DIR} is not defined AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf: Invalid Mutex directory in argument file:${APACHE_LOCK_DIR} Defined variables shouldn't be the problem because they get initialised by running apache2, but the mutex directory seems to be fine.. – Martijn H. Jan 31 '14 at 12:45
  • Dont forget that i CAN visit the webpage, only the subdomain is linked to the main domain instead of the folder subdomains – Martijn H. Jan 31 '14 at 12:51
  • I'm sorry. I'm am a bit blank on your problem then :( Have you tried turning it off and on again? Just kidding. I'm assuming you have restarted the server after editing the files. – Bjarke Brask Rubeksen Jan 31 '14 at 15:23