February 08, 2010 by Dave
    

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! 

 


6 Comments

trying

Mar 15 2010 at 08:47 PM

hi,
this doesn't seem to work for me

trying

Mar 15 2010 at 09:49 PM

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

Dave

Aug 20 2010 at 03:10 AM

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

Kausik

May 19 2011 at 01:11 PM

is there any need to restart apache server after doing this

Dave

Jul 12 2011 at 08:06 PM

@Kausik - Nope, changes to .htaccess should be immediate as long as Apache's AllowOverride is working properly.

Cumpanasu Florin

Nov 06 2011 at 12:42 AM

Not working for me. Instead of running, he is downloading the file.php


Add A Comment





Completely Private, used for Gravatar



example: https://www.whatever.com