I'm trying to setup apache2 to host multiple sites, but using the same root-URL and differing in subfolder only, i.e.

hxxp://example.com/site1/

hxxp://example.com/site2/

It should be easy but I have, after several hours of googling, still not found the right way how to do this. I can find site1 by surfing to http://example.com but not the other one at all.

I'm using kubuntu server 10.04 and have made conf files in /etc/apache2/sites-available/ and run a2ensite for each site

Is it a .htaccess related problem or do I have to fiddle around with the apache2 conf-files?

link|improve this question
feedback

2 Answers

up vote 0 down vote accepted

The "problem" is that you use VirtualHosts for something it wasn't really designed for. http://httpd.apache.org/docs/2.2/en/vhosts/ A "site" is defined by a own Domain OR IP. So if you make a VirtualHost config for a subfolder (like you) there is a conflict (dunno what your decision factor is? I mean ServerName/ServerAlias). I don't know what exactly happens, but the things you configured in the VirtualHosts will not work as they should (at least not all of them). So what's the solution(s):

  • You could use subdomains like site1.example.com and site2.example.com (if you want to work with VirtualHosts)
  • You could use 1 VirtualHost (for example.com) and Directory for your subsites (example.com/site1 and example.com/site2): http://httpd.apache.org/docs/2.0/en/mod/core.html#directory BUT you don't have the same options here as in a VirtualHost config.
  • Probably there are other solutions, but my ones should solve the problem ;)

Hope this helps.

Btw.

kubuntu server 10.04

You shouldn't use a X-Server on a production system, better for security and performance.

link|improve this answer
Thanks for your explanation, now I have a somewhat better understanding of how this is supposed to work! I'll go for your second solution since I'm on an intranet! – Jonas Hallgren Dec 1 '10 at 13:00
feedback

After som trial and error I have succeeded in what I wanted to do, by changing the line

DocumentRoot /var/www/site1

to

DocumentRoot /var/www

in both site-conf files (in /etc/apache2/sites-available)

But I have to admit that I have no idea if this will have other effects to my overall setup/security/performance.

Any clues?!

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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