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?

link|improve this question

72% accept rate
feedback

2 Answers

up vote 2 down vote accepted

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.

link|improve this answer
Removed mod_routing, evaluating the rest of you answer. I'll try out Aliases. – ripper234 Jan 2 at 12:02
On ubuntu, the solution was editing mods-enabled/alias.conf and adding Alias /foo2 "/var/www/foo2". Thanks! – ripper234 Jan 2 at 12:15
feedback

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.

link|improve this answer
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. – ripper234 Jan 2 at 10:40
There are many documentation on using mod_rewrite. You can start using it and if you need help you can ask another question. – Khaled Jan 2 at 10:45
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.