11

I have two applications running in the same server and I would like to have one served from subpath in the url (i.e):

  • foo.com -> /var/www/foo
  • foo.com/bar -> /var/www/bar

I'm trying to do an alias but is not working:

<VirtualHost *:80>
  ServerAdmin webmaster@foo.com
  ServerName foo.com
  DocumentRoot /webapps/foo/current/public
  <Directory /webapps/foo/current/public>
    AllowOverride all
    Options -MultiViews
  </Directory>
  RailsEnv staging
  Alias /blog /webapps/blog/current
 <Directory /webapps/blog/current>
   allow from all
   Options +Indexes
 </Directory>

Do you know why this is not working?

I also tried serverpath directive without any success.

Do you know how to achieve this?

Thanks in advance.

Rafael
  • 614
  • 2
  • 7
  • 13
  • 2
    Is your virtualhost working at all? Cos if you need to access it via `www.` as well as the root of the domain, I would say you need a `ServerAlias www.foo.com` in there... – DaveRandom Aug 26 '11 at 17:52
  • Also, does either app use any `mod_rewrite`ing? – DaveRandom Aug 26 '11 at 17:56
  • Oh sorry, actually the address is without the www. I fixed that on the post. The virtualhost is working, I'm able to access it, but if I go to /blogs/ it does nothing. Both applications have mon_rewrite inside their .httaccess – Rafael Aug 26 '11 at 19:02
  • What do you get? A 404? And what is in the Apache logs? And are you using a `[PT]` on you rewrite rules for the `/blogs` directory? – DaveRandom Aug 26 '11 at 19:09
  • I get a 404 that is handled by /var/www/foo. I don't have a [PT] rewrite rule. Actually I don't have a rewrite for the /blog... I'm using for other things. Should I have a rewrite and the alias in order to make it work? – Rafael Aug 26 '11 at 20:21
  • Not necessarily, it depends on your app - it's just that some rewrite rules wont work with aliases unless you have a `[PT]` (although not all rules, it depends on what it does). Let me have a play with the Apache install on my laptop and I'll get back to you... – DaveRandom Aug 26 '11 at 20:30
  • what about using a subdomain such as bar.foo.com. This way it will have its own vhost configuration. – minaz Aug 29 '11 at 03:26
  • the subdomain is the way I have it know, but we wanted to change it to the other way. – Rafael Sep 02 '11 at 21:20
  • Besides tuning apache configuration, have you ever tried create a symbolic link `/var/www/bar` to `/var/www/foo/bar` – stanleyxu2005 Oct 12 '14 at 08:28

2 Answers2

3

Use AliasMatch instead of Alias:

AliasMatch ^/bar/?(.*) /var/www/bar/$1

Or, in your case:

AliasMatch ^/blog/?(.*) /webapps/blog/current/$1
Niklas Lindblad
  • 1,031
  • 6
  • 9
1

Have you considered using another separate subdomain, like bar.foo.com for your other application?

Here's how you'd set that up:

<VirtualHost *:80>
    ServerAdmin webmaster@foo.com
    DocumentRoot /var/www/foo
    ServerName foo.com
    ServerAlias foo.com www.foo.com
    ErrorLog logs/foo.com_Error_Log
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@foo.com
    DocumentRoot /var/www/bar
    ServerName bar.foo.com
    ErrorLog logs/bar.foo.com_Error_Log
</VirtualHost>
user3666197
  • 1
  • 6
  • 50
  • 92