Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I host 40+ sites on a single server, each site being it's own Joomla installation (managed by a central distribution system, of course). Every site is in it's own directory, /var/www/<site>. Some sites have their own domains, which are configured by defining VirtualHosts.

Most sites don't have their own domains, but rather use a subdirectory under my main domain as their url, http://mysite.fi/<site>

I also have one main site that handles every request to /, this is located at /var/www/main. So currently when user requests http://mysite.fi they're redirected to http://mysite.fi/main.

I would like for this to be transparent. When user requests a valid http://mysite.fi/<site> they should of course see that site. But if they request http://mysite.fi/mainsitearticle that request should then go to the site at /var/www/main, and it should remain transparent so that the user's URL doesn't change.

One way that this result is possible to implement with correct results is by symlinking everything under /var/www/main directly to /var/www, so the sever actually thinks there's a Joomla living at /var/www. But this isn't a very elegant solution.

To recap what I want:


http://mysite.fi/kiwi/ -> /var/www/kiwi/
http://mysite.fi/apple/ -> /var/www/apple/
http://mysite.fi/apple/somearticle -> /var/www/apple/ (*)
http://berry.fi/ -> /var/www/berry/
http://mysite.fi/ -> /var/www/base/
http://mysite.fi/some_article_name -> /var/www/base/ (*)
http://mysite.fi/images/thelogo.png -> /var/www/base/images/thelogo.png

(* = final request handled by Joomla's .htaccess mod_rewrite rules)

So what would be the elegant way to configure this behaviour?

share|improve this question

1 Answer 1

Assuming you are using apache2 and have mod_alias and mod_rewrite enabled

Something like the following in the main virtualhost should work:

# folders in /var/www/ are case sensitive and can only contain a-zA-Z0-9 or hyphen (-)
# Anything else is redirected 'home'

AliasMatch     ^/([[:alnum:]\-]+)(/?.*)    /var/www/$1

RewriteEngine on

RewriteCond    /var/www/$1                  !-d
RewriteRule    ^/([[:alnum:]\-]+)(/?.*)    http://mysite.fi/ [L,R]  # Doesn't match a directory in /var/www -- redirect home

The AliasMatch line may need some tweaking depending on what you allow in your sub-folder names.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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