Hulihan Applications
about projects portfolio services contact_us
Running PHP Inside a Rails App

    

Have you ever wanted to run a PHP application inside of a Rails application? Here's a scenario: your website is written in ruby on rails. You want to run a php application, like Magento inside it, under a directory called shop. Since all web-accessible files in Rails are located in the public directory, your shop directory will be located in public/shop. However, whenever you try to access this directory by going to http://www.yourwebsite.com/shop, You get a 500 error from your Rails application saying: Application error Rails application failed to start properly, or something along those lines. 

Uh Oh.

This is because rails thinks that this subdirectory is a controller or an action within your rails application that isn't acting properly, when in reality, it's a real subdirectory with PHP files inside! We need to convince it otherwise. The easiest way to do this is by creating an .htaccess file inside the shop directory. Then paste this code into the .htaccess file:

RewriteEngine On
RewriteRule ^([^\.]+[^/])$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_URI} !^/-
RewriteCond %{DOCUMENT_ROOT}/-%2 -d
RewriteRule ^(.*)$ -%2/$1 [QSA,L]

That's it! Try it again, and your PHP code should run without a problem! 

 



3 Comments

Dave says...
Have you tried adding DirectoryIndex index.php to the .htaccess file?

trying says...
it does work, thank you! however, although /shop/index.php seems to work, just /shop/ does not.

trying says...
hi, this doesn't seem to work for me


Add A Comment



simple_captcha.jpg



Hulihan Applications © 2007-2009
No portion of this site may be copied, altered, duplicated or otherwise used without the express written approval of Hulihan Applications.