The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Redirecting http to https give loop error

Discussion in 'General Discussion' started by Louie Picklezilla, Sep 7, 2015.

  1. Louie Picklezilla

    Louie Picklezilla Registered

    Joined:
    Sep 7, 2015
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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?
     
    #1 Louie Picklezilla, Sep 7, 2015
    Last edited by a moderator: Sep 7, 2015
  2. TubeNations

    TubeNations Member

    Joined:
    Sep 8, 2015
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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 :)
     
  3. MilesWeb

    MilesWeb Well-Known Member
    PartnerNOC

    Joined:
    May 23, 2012
    Messages:
    174
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    India
    cPanel Access Level:
    Root Administrator
    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]
     
    cyberview likes this.
Loading...

Share This Page