Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell Rails to ignore particular URL and let Apache handle

I have a rails app running on my Apache server via Passenger.

Occassionally I am using some PHP scripts for the website, and have placed them in the public directory.

When I go to /php/ I want Apache to handle the request with the PHP parser and have rails ignore it.

Currently I can go to /php/index.php and it works fine. However I need /php/ to work as well but rails keeps looking for the controller to handle it.

I have a feeling this is something to do with apache rewrite rules, but I cant figure it out.

I have used

RewriteEngine On 
RewriteRule ^php - [L] 
RewriteBase / 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

in the /php/.htaccess file but this doesnt work. I still get the page not found error by Rails.

like image 710
Nick Barrett Avatar asked Dec 08 '25 15:12

Nick Barrett


1 Answers

I think you can do this in your Passenger app's main Apache config file - something along the lines of this

<Directory "/.../myapp/php">
    PassengerEnabled off
    AllowOverride all
</Directory>

inside your VirtualHost block should do the trick (of turning Rails off, at least - turning PHP on is up to you!).

My answer is based off the ModRails Apache documentation - see section 5.6 for more on the PassengerEnabled command.

like image 189
Xavier Holt Avatar answered Dec 11 '25 13:12

Xavier Holt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!