---
title: Phusion Passenger with a prefix
teaser:
tags: web,rails
author: Mike Burns
published_on: 2008-09-19
---

The [Mongrel](http://mongrel.rubyforge.org/) Web server can run with a <abbr
title="Uniform Resource Locator">URL</abbr> prefix, [using the --prefix
option](http://mongrel.rubyforge.org/wiki/FAQ#HowdoIputmyRailssiteatsomeprefix).
This is useful for running an app in a "subdirectory"&mdash;say BankDirectr at
`http://banks.info/directr` and BankRobbr at `http://banks.info/robbr` .

![Lola robbing a store in Run Lola Run][lola]

[lola]: http://images.thoughtbot.com/ui/2008-9-19-300px-Runlolarun.jpg

In development you want that same prefix; this way your stylesheets, images, and
other static assets show correctly at the right <abbr title="Uniform Resource
Locator">URL</abbr>. For this we had originally modified `script/server` to
always pass --prefix to Mongrel.

Switching to [Phusion Passenger](http://www.modrails.com/) has removed one tab
from [my screen
session](http://mikeburnscoder.wordpress.com/2007/06/21/my-rails-development-environment-version-1-vim-and-screen/),
and made [development faster and
easier](http://railscasts.com/episodes/122-passenger-in-development). However,
getting it to work with a subdirectory took a few minutes.

The basic idea is that [Apache](http://httpd.apache.org/) handles the static
assets, and Passenger handles the rest. So in your
[`VirtualHost`](http://httpd.apache.org/docs/2.2/mod/core.html#virtualhost)
block you need to add an
[`Alias`](http://httpd.apache.org/docs/2.2/mod/mod_alias.html#alias) from the
prefix to the
[`DocumentRoot`](http://httpd.apache.org/docs/2.2/mod/core.html#documentroot).
Like this:

```xml
<VirtualHost *:80>
  ServerName banks.info
  DocumentRoot /var/www/robbr
  Alias /robbr /var/www/robbr
</VirtualHost>
```

However, in an attempt to ruin our fun, [Phusion Passenger's documentation says
this](http://www.modrails.com/documentation/Users%20guide.html#_mod_rewrite_and_mod_alias):

> Phusion Passenger conflicts with `mod_rewrite` and `mod_alias`. Those modules
> may be installed and loaded together with mod_passenger, and they will work
> fine outside virtual hosts that contain a Rails application, but we recommend
> you not to use their features inside virtual hosts that contain a Rails
> application.

Fine. It works just fine for me using `mod_alias`, but that's only in my
development environment and not in production. Here's another solution:

    cd /var/www/robbr/public
    ln -s . robbr

Now any asset that references `/robbr` , such as `/robbr/stylesheets/layout.css`
, will follow the symlink to `public` .
