I've 2 sub domains both are pointing on same ip and server and currently pointing to /var/www/html as root but I want one of them to point in subdirectory like /var/www/html/anothersub :

So I created new file in sites-available folder : anothersub.mydomain.com.conf

added this above code in it :

<VirtualHost *:80>
        ServerName anothersub.mydomain.com
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/html/anothersub
        <Directory /var/www/html/anothersub>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all

        ErrorLog ${APACHE_LOG_DIR}/red-error.log

        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/red-access.log combined


and run commands : sudo a2dissite anothersub.mydomain.com.conf sudo a2ensite anothersub.mydomain.com.conf sudo service apache2 restart

but still my both domains are pointing to same root directory


Add a slash to the end of the Directory path:

<Directory /var/www/html/anothersub/>

Make sure both VirtualHost files are in /etc/apache2/sites-enabled:

ls -al /etc/apache2/sites-enabled

If one of the VirtualHosts should not be in this directory enable it:

a2ensite anothersub.conf

Note that the config file has to have the file extension .conf, otherwise it will not work! Restart your apache2 webserver

service apache2 restart

Call both domains, e. g. with curl:

curl -I mydomain.com
curl -I anothersub.mydomain.com

If it doesn't work have a look at the apache log files:

tailf /var/log/apache2/red-access.log

Hope this helps

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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