Httpd – How to configure multiple directories on Apache

apache-2.2configurationhttpd

I'm working on ubuntu with apache2.

Requirements

  1. The root directory should be served from a specific folder. When someone accesses http://mysite.com/foo1 he should reach /var/www/tld/foo1
  2. Other directories as sub-sites: When someone accesses http://mysite.com/subsite/foo2 he should reach /var/www/subsite/foo2
  3. I would like to be able to configure specific shortcuts for some actions. E.g. by adding a custom rule, I would like http://mysite.com/foo3 to reach http://mysite.com/subsite/foo3 (unlike #1, this is not global, but just by adding specific routes).

What's the best way to achieve this? Should I have a different file under apache/site-enabled per "subsite"? Or should I use <Directory>? How do I configure mod_rewrite to achieve this?

Best Answer

A virtualhost has only one documentroot; apache has no concept of "subsites".

Vhosting documentation

You can make exceptions to this by adding an Alias that points to a filesystem location outside the documentroot, but take care in what order you define these: the first match wins, so you should order them from most specific to least specific.

Alias documentation

The last question is more a case of bad site layout, but you could issue a Redirect for it:

Redirect /foo3/ /subsite/foo3/

There is no module named mod_routing in apache.