Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting to HTTPS returns error "too many redirects"

I am trying to force https via htaccess and am getting a "too many redirects" error. Below is what I am using to try to accomplish this.

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Any ideas on how I can accomplish this or why this doesn't seem to be working?

Edit: I followed the answers from here Force https://www. for Codeigniter in htaccess with mod_rewrite which seems to be causing the redirect loop for me. When I remove this part:

RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The redirect loop goes away; however it isnt redirecting to https.

like image 514
Mike Avatar asked Sep 15 '15 14:09

Mike


People also ask

Why do I keep getting Err_too_many_redirects?

The ERR_TOO_MANY_REDIRECTS error indicates that the browser is stuck in an infinite redirection loop. An infinite redirection loop happens when you visit a URL pointing to another URL, which points back to the first one.


1 Answers

I can not say for sure if this is related to a (or some) hosting provider/s, but none of the solutions worked for me. Coz of restriction of hosting provider, I could not get the apache version except it was 2.x.

This is what did, maybe helpful to someone:

RewriteEngine On
RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
like image 167
pipepiper Avatar answered Oct 11 '22 13:10

pipepiper