How to configure multiple directories on Apache?

9,450

Solution 1

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.

Solution 2

If all URLs are hosted under the same domain/IP address, you can use mod_rewrite to rewrite the URLs according to the rules you specify.

Share:
9,450

Related videos on Youtube

Craig Vermeer
Author by

Craig Vermeer

Updated on September 18, 2022

Comments

  • Craig Vermeer
    Craig Vermeer over 1 year

    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?

  • Craig Vermeer
    Craig Vermeer over 12 years
    See above (Replaced mod_routing with mod_routing/mod_rewrite): How do I configure mod_routing/mod_rewrite to achieve this? You can tell me to RTFM if you want.
  • Craig Vermeer
    Craig Vermeer over 12 years
    On ubuntu, the solution was editing mods-enabled/alias.conf and adding Alias /foo2 "/var/www/foo2". Thanks!