How to configure multiple directories on Apache?
Solution 1
A virtualhost has only one documentroot; apache has no concept of "subsites".
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.
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.
Related videos on Youtube
Craig Vermeer
Updated on September 18, 2022Comments
-
Craig Vermeer over 1 year
I'm working on ubuntu with apache2.
Requirements
- The root directory should be served from a specific folder. When someone accesses http://mysite.com/foo1 he should reach
/var/www/tld/foo1
- Other directories as sub-sites: When someone accesses http://mysite.com/subsite/foo2 he should reach
/var/www/subsite/foo2
- 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 configuremod_rewrite
to achieve this? - The root directory should be served from a specific folder. When someone accesses http://mysite.com/foo1 he should reach
-
Craig Vermeer over 12 yearsSee above (Replaced
mod_routing
withmod_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 over 12 yearsOn ubuntu, the solution was editing
mods-enabled/alias.conf
and addingAlias /foo2 "/var/www/foo2"
. Thanks!