2

I want to redirect couple of pages to https. As I've already use one condition to redirect all requests to http, for those coupoe of pages, it shows too many redirects. Look at my code below:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ www.example.com/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^login\.php$ https://www.example.com/login.php

This doesn't work. "Too many redirects". Anyone can help?

zx81
  • 38,175
  • 8
  • 76
  • 97
Shanil Soni
  • 935
  • 10
  • 35

1 Answers1

2

The first rule makes no sense.

Shorten to this:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^login\.php$ https://www.example.com/login.php [L,R]

If the idea of the first rule was to force www, add this:

# From http://stackoverflow.com/a/4958847/1078583
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
zx81
  • 38,175
  • 8
  • 76
  • 97