Redirect /user/login to HTTPS, all other requests to HTTP I'm using Drupal 7. The login page for my users is located at /user/login, so the default login path.  I need that page to be encrypted using SSL so people aren't transmitting their passwords in the clear.

I have Apache configured so that the site can be navigated either over HTTP or HTTPS.  However, I want to implement some rewrite rules so that all requests other than /user/login are made over HTTP because it is INFINITELY faster and will result in better user experience.  I refuse to use Secure Pages at this point in time because of the bugged support in Drupal Core and I'm not going to patch Core manually.  That means I'm left with using Apache rewrite rules.

I have the following rules:

&lt;VirtualHost *:80&gt;
  ...
  RewriteCond %{HTTPS} off
  RewriteCond %{REQUEST_URI} ^/user/login$
  RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [L,R]
  ...
&lt;/VirtualHost&gt;

&lt;VirtualHost *:443&gt;
  ...
  RewriteCond %{HTTPS} on
  RewriteCond %{REQUEST_URI} !^/user/login$
  RewriteRule ^/(.*) http://%{HTTP_HOST}/$1 [L,R]
  ...
&lt;/VirtualHost&gt;


Now to me, that makes sense, but Drupal doesn't seem to like it.

What's happening is as follows:


If I navigate around the site using HTTP to any page other than /user/login, it works fine.
If I navigate to /user/login over HTTP, I get redirected to the front page.
If I navigate to any page over HTTPS, I get redirected to the front page over HTTP.
You don't really need /user/login to be served via https; you need the user login form to be submitted via https.

You should take a look at the module securepages_prevent_hijack -- not to use it directly, since it depends on securepages, but to see how the login form is altered.  Like so:

function securepages_prevent_hijack_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  // Secure the login form, so that we always have a secure connection to transmit the
  // initial cookie.  Also, protect the password in transit.
  if ($form['#id'] == 'user-login-form' || $form['#id'] == 'user-login') {
    $url = parse_url($form['#action']);

    $base_path = base_path();
    $path = (!strncmp($url['path'], $base_path, drupal_strlen($base_path)) ? drupal_substr($url['path'], drupal_strlen($base_path)) : $url['path']);
    $options = array('secure' =&gt; TRUE);
    if (isset($url['query'])) {
      $options['query'] = $url['query'];
    }
    $form['#action'] = securepages_url($path, $options);
  }
}


You should also figure out whether the cookie that Drupal is setting for you is secure or not.  This will depend on your settings in php.ini.  Check to see if you have set session.cookie_secure to 1.  If you have, then the cookie will not be sent to your http sessions, which could be why you are ending back at the home page (no session cookie == no session == no login info == log out).  Of course, if the session.cookie_secure is 0, then it might be possible for other parties to observe your session cookies in transit, and masquerade as your users.  Perhaps you have already considered this risk, but it does bear some consideration.