Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache alias virtual host

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.

like image 979
Rafael Avatar asked Aug 26 '11 17:08

Rafael


People also ask

What is an Apache virtual host?

The Apache HTTP server supports virtual hosts, meaning that it can respond to requests that are directed to multiple IP addresses or host names that correspond to the same host machine. You can configure each virtual host to provide different content and to behave differently.

How do you name a virtual host?

To use name-based virtual hosting, you must designate the IP address (and possibly port) on the server that will be accepting requests for the hosts. This is configured using the NameVirtualHost directive.

What are the types of virtual hosts in Apache?

There are two types of virtual hosts on Apache: IP-Based Virtual Hosting – every individual website on the Apache Server uses a different, unique IP address. Name-Based Virtual Hosts – enables you to add multiple domains using a single IP address.


1 Answers

Use AliasMatch instead of Alias:

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

Or, in your case:

AliasMatch ^/blog/?(.*) /webapps/blog/current/$1
like image 75
Niklas Lindblad Avatar answered Oct 05 '22 22:10

Niklas Lindblad