Set up Apache2 to server multiple directories on the same domain based on URL path
I want to host two different sites on the same IP, same server, and same domain using Apache2 on Ubuntu Linux. Let's say I have the following directories which represent sites that will serve content:
/srv/www/blog/ #for the blog
/srv/www/mainsite/ #for the main site
I want to set up Apache2 so that the following applies:
- When a user visits
http://mysite.com/
they are served content from/srv/www/mainsite/
. - When a user visits
http://mysite.com/blog
, they are served content from/srv/www/blog/
.
I had thought I was going to be setting up multiple virtual hosts, but only seems to apply for distinct domains and/or IPs. What do I need to do in my apache2 configuration to achieve the above functionality?
Solution 1:
Inside your <VirtualHost>
:
DocumentRoot /srv/www/mainsite
<Directory /srv/www/mainsite>
Order Allow,Deny
Allow from all
</Directory>
Alias /blog /srv/www/blog
<Directory /srv/www/blog>
Order Allow,Deny
Allow from all
</Directory>
Ignore the directory blocks if you already have one that covers /srv/www
- I just put them in to make it clear that you'll need Apache's access controls allowing access to both.