Apache alias virtual host

Rafael picture Rafael · Aug 26, 2011 · Viewed 18k times · Source

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 [email protected]
  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.

Answer

Niklas Lindblad picture Niklas Lindblad · Nov 1, 2013

Use AliasMatch instead of Alias:

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

Or, in your case:

AliasMatch ^/blog/?(.*) /webapps/blog/current/$1