Redirecting http to https give loop error

Louie Picklezilla

Registered
Sep 7, 2015
1
0
1
United Kingddom
cPanel Access Level
Website Owner
I am trying to force my website to redirect to https automatically, but it gives a loop error when I try to do so. I've tried so many different things and nothing is working.

My .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^too\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.too\.com$
RewriteRule ^(.*)$ "https\:\/\/toon\.com\/$1" [R=301,L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
DirectoryIndex play

How do I get it to work?
 
Last edited by a moderator:

TubeNations

Member
Sep 8, 2015
6
0
1
United Kingdom
cPanel Access Level
Website Owner
Twitter
I use a php snippet of code and htaccess for my redirect to https://www.

in my htaccess i have

Code:
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.sitenamehere.com$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ sitenamehere/$1 [L,R=301]
And in my header.php i got this snippet of code.

PHP:
<?php
if (! isset($_SERVER['HTTPS']) or $_SERVER['HTTPS'] == 'off' ) {
    $redirect_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    header("Location: $redirect_url");
    exit();
}
?>
before i used both of these methods, i tried many methods in htaccess, but i had soo many issues, but now this 2 bits above does the trick for me, maybe it will help you too :)
 

MilesWeb

Well-Known Member
PartnerNOC
May 23, 2012
173
2
68
India
cPanel Access Level
Root Administrator
Twitter
Hi Louie, Welcome to the forums.

Below is the code you can enter in your .htaccess file.

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://www.%1%{REQUEST_URI} [L,R=301]
 
  • Like
Reactions: cyberview