Rails and PHP Under the Same Domain Name with Fast CGI

Hello,

Inspired by this post, I created the following Apache vhost to be able
to run Rails and, inside /app/public, the PHP posh app.

<VirtualHost *:80>
ServerName dev.example.com
DocumentRoot “/home/www/projets.example.com/projets/
portfolio_immigrants/public”

SuexecUserGroup examplewww examplewww
ScriptAlias /fast-cgi/ /home/www/projets.example.com/cgi-bin2/

<Directory "/home/www/projets.example.com/projets/

portfolio_immigrants/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

<Proxy balancer://dev_example_com_cluster>
BalancerMember http://127.0.0.1:6080
# BalancerMember http://127.0.0.1:6081
# BalancerMember http://127.0.0.1:6082

ProxyPass /fast-cgi !
ProxyPass /posh !

RewriteEngine On
RewriteLog "/var/log/httpd-rewrite.log"
RewriteLogLevel 3
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} \.php
RewriteRule ^(.*)$ $1 [QSA,L]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.html -f
RewriteRule ^(.*)$ $1/index.html [QSA,L]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.php -f

RewriteRule ^(.*)$ $1/index.php [QSA,L]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d
RewriteRule ^(.*)[^/]$ $1/ [QSA,L]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://dev_example_com_cluster%{REQUEST_URI}

[P,QSA,L]

I’m running on the server FreeBSD, Apache2, FastCGI, SuExec, Rails
2.0.2 and Mongrel.

The problem is that I can’t find a way to makes mod_rewrite ignore
the /fast-cgi/ ScriptAlias. Thus, when looking at the mod_rewrite log,
I see the following:

init rewrite engine with requested uri /fast-cgi/php5.fcgi/posh/
index.php
applying pattern ‘^(.+[^/])$’ to uri ‘/fast-cgi/php5.fcgi/posh/
index.php’
applying pattern ‘^(.*)$’ to uri ‘/fast-cgi/php5.fcgi/posh/index.php’
rewrite ‘/fast-cgi/php5.fcgi/posh/index.php’ → ‘/fast-cgi/php5.fcgi/
posh/index.php’
local path result: /fast-cgi/php5.fcgi/posh/index.php
prefixed with document_root to /home/www/projets.example.com/projets/
portfolio_immigrants/public/fast-cgi/php5.fcgi/posh/index.php
go-ahead with /home/www/projets.example.com/projets/
portfolio_immigrants/public/fast-cgi/php5.fcgi/posh/index.php [OK]

I have tried with ProxyPass /fast-cgi ! with no success. The Rails app
works fine.

TIA

Ok, I finally figured out the solution.

Simply add this rule at the top of the mod_rewrite rules.

RewriteCond %{REQUEST_URI} ^/fast-cgi/
RewriteRule ^(.*)$ $1 [QSA,L,PT]

QSA = query string append
L = stop processing after this rule
PT = passthrough, let ScriptAlias handle the request

PS: the post I was referring to in the first post of this thread is
this one:
http://groups.google.com/group/rubyonrails-talk/msg/99b36051504f783f

Cheers
-Emmanuel