Domain – Apache : Making one virtual host subdomain/subdirectory of another virtual host

apache-2.2djangodomainsubdomainvirtualhost

My setup is a bit awkward. I've got http://sub.main.com mapped to my server's IP but not the http://main.com. I am running two sites on my server(using different web frameworks). For each of those sites I've got virtual hosts configured in default site, which looks something like this.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    ServerName "sub.main.com"
    DocumentRoot "/var/www"
    ....
</VirtualHost>

<VirtualHost *:80>
    ServerName appsphere.djangoserver
    Alias /media /srv/www/appsphere/media/
    ......
    ......
    WSGIScriptAlias / /srv/www/appsphere/apache/django.wsgi

</VirtualHost>

Now how can I make my second virtual host a subdirectory/subdomain of first virtual host. I want to access the second site using http://sub.main.com/appsphere

Best Answer

Change your first VirtualHost declaration to the following:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    ServerName "sub.main.com"
    DocumentRoot "/var/www"

    Alias /appsphere/media /srv/www/appsphere/media
    WSGIScriptAlias /appsphere /srv/www/appsphere/apache/django.wsgi

</VirtualHost>