# Rails and PHP Under the Same Domain Name with Fast CGI

**URL:** <https://www.ruby-forum.com/t/rails-and-php-under-the-same-domain-name-with-fast-cgi/136982>\
**Category:** Rails\
**Created:** [May 7, 2008, 10:14pm UTC](https://www.ruby-forum.com/t/rails-and-php-under-the-same-domain-name-with-fast-cgi/136982 "2008-05-07T22:14:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmanuel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3e96dc/32.png) [@emmanuel](https://www.ruby-forum.com/u/emmanuel)\
**Post date:** [May 7, 2008, 10:14pm UTC](https://www.ruby-forum.com/t/rails-and-php-under-the-same-domain-name-with-fast-cgi/136982/1 "2008-05-07T22:14:52Z")

</div>

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](http://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](http://127.0.0.1:6080)  
# BalancerMember [http://127.0.0.1:6081](http://127.0.0.1:6081)  
# BalancerMember [http://127.0.0.1:6082](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

---

<div class="post-metadata">

**Author:** ![emmanuel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3e96dc/32.png) [@emmanuel](https://www.ruby-forum.com/u/emmanuel)\
**Post date:** [May 8, 2008, 6:30pm UTC](https://www.ruby-forum.com/t/rails-and-php-under-the-same-domain-name-with-fast-cgi/136982/2 "2008-05-08T18:30:33Z")

</div>

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](http://groups.google.com/group/rubyonrails-talk/msg/99b36051504f783f)

Cheers  
-Emmanuel
