Apache rewrite rule to redirect https to http for pages you don’t need https


You are using your Rails 3.2.x application with Apache and you have setup force_ssl in one of your controllers (ie payments), that you want to force the application to use ssl. But after you set it up, and you go to one of the actions for that controller, every subsequent page you follow still uses the https protocol, even if you don’t want them to.
So you need a way to force the serving of pages in http.


You can use a redirection in your SSL apache conf file, and specify that when it doesn’t match the sections (controller,actions) you specify it should be redirected to http.
Note that RewriteCond in Apache are by default ANDed when they are in subsequent lines so you can add more conditions and that you can use [OR] if you want to perform an OR logic operation.
So by adding the following in your virtual host for the 443 port (ssl), and apply the changes it should be working as expected:

# Add https to http redirection
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/controller_you_want_ssl.*
RewriteRule (.*)  http://%{HTTP_HOST}%{REQUEST_URI}

Rails Passenger Staging environment problem in Dreamhost

You want to deploy your rails application using Passenger in Dreamhost, but on a staging environment. It doesn’t work just changing your Capistrano recipe or your environment files, as the default environment for passenger is ‘production’.

Looking at the Passenger documentation here, there are four different ways of achieving that by changing the RailsEnv option. If you don’t want to change the Apache configuration files, and as long as the option AllowOverride is on (which should be on Dreamhost), then you would need to create an .htaccess file in your application’s public folder with the following:

RailsEnv staging

Phusion Passenger installation in Mandriva 2009

You have recently installed Mandriva 2009 and you want to install phusion passenger.


  1. First make sure that apache is installed. If it is not installed (default), do:
    urpmi apache

    On the selection question about the dependencies select option 1 (apache-prefork)

  2. Use the details from the phusion passenger website. ie:
    Install passenger:

    gem install passenger
  3. Run the passenger installation:
  4. If at the second stage of the installation the installer complains that GNU C++ compiler … not found, install the gnu c++ compiler, with:
    urpmi gcc_c++
  5. Run the passenger installation (step 3) again. If at this stage the installer complains that Apache 2 development headers … not found, use:
    urpmi apache-devel
  6. Run passenger installer (step 3), once more. Now everything should be ok and the apache 2 module will be installed when the installer finishes.
  7. Restart the Apache webserver, and you should be able to add your Rails application. Use the following to deploy your application in /somewhere/public:
    <VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public

Disabling rails web site when using mongrel,Apache,capistrano 1.4.1

You want to disable your rails web site for maintenance, but your application uses an older capistrano version than the one currently installed.

According to the RubyOnRails Cookbook recipe 13.12, it should only be a case of running cap disable_web (enable_web).
But in the meantime you have upgraded your capistrano version to version 2, and started using mongrel server as well.
So if you are using virtual severs and proxy with mongrel, the first thing to do is add the following in your Apache configuration file:

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [R]

If you needed to make the above change then you will have to restart apache in your server.

Then in your local pc you can run the following:

export REASON="Maintenance for MySQL upgrade"
export UNTIL="Sat May 10 15:30:00 2008"
cap _1.4.1_ disable_web (to put it in maintenance)
cap _1.4.1_ enable_web (to restart it again)