0

I am trying to redirect only a login page on my site from http to https

The site is load-balanced on 2 servers, and when I enable the rewrite rule on one webserver, things work fine. When I enable the identical rule on both servers, it seems to break the page - it never loads, caught in a loop.

What I intend to do is:

  1. Check if the page requested is HTTPS
  2. Redirect to https://example.net/login/ if the requested page is one of these:

    http://example.net/login

    http://example.net/login/

    http://example.net/login/index.html

Here's the rule I created, copied and pasted onto both servers identically in httpd.conf

  <Directory "/var/www/html">

       RewriteEngine On

       RewriteCond %{HTTPS} =off
       RewriteRule ^login(/index.html|/)?$ https://example.net/login/ [R=301,L]

       . . . many more redirect rules below 
       RewriteRule ^something-more(.*)$ /ok-whatever/$1 [R=301,L] 

Can you see what the problem might be ? Is it something about the load-balancing that is throwing this into a loop ? For example is %{HTTPS} not being updated ?

Thanks,

jeph perro
  • 6,242
  • 26
  • 90
  • 124
  • can't you juse specify a simple redirection in the appropiate virtualhost and use a simple RedirectMatch? That way you do not have to check if the request is ssl or not, since you will define it in the non-SSL virtualhost directly, and the redirection is simple enough to not need mod_rewrite. Abusing per-dir configurations lead to unnecessary complication and loss of hair. – Daniel Ferradal Jan 27 '17 at 14:31
  • also note if you own "example.net" that can loop. – Daniel Ferradal Jan 27 '17 at 14:33

0 Answers0