Thread

EE3 - Infinite loop created when forcing https:// in htaccess

November 01, 2017 11:08am

Subscribe [2]
  • #1 / Nov 01, 2017 11:08am

    Kubik101's avatar

    Kubik101

    155 posts

    I have developed plenty of sites on EE2 and used the following htaccess code to force https:// with no issues.

    Now in EE3 (to which I am very green in) when I use the force https:// code it creates an infinite loop.

    It is as if something in the EE CMS is forcing the https:// to go http:// thus creating the loop.

    I have all my path settings in EE3 set to https:// so I don’t know what could be causing it.

    Below is the htaccess code I am using.

    Any ideas?

    Thanks.

    <IfModule mod_rewrite.c>
    
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTPS} !=on
    RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # Canonical www
    RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    
    # Removes index.php from ExpressionEngine URLs
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/x74fg3xvsp94F334/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
    
    # Directs all EE web requests through the site index file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    
    </IfModule>
  • #2 / Nov 01, 2017 5:45pm

    Derek Jones's avatar

    Derek Jones

    7176 posts

    ExpressionEngine doesn’t perform any redirects on its own, so it’s likely server config related. I think you mean RewriteCond %{HTTPS} !on instead of RewriteCond %{HTTPS} !=on? Otherwise nothing gets my attention, except that if your web server is not setting the HTTPS environment variable at all, you’d be constantly redirecting.

    I often use these two tools to help me nail down .htaccess woes:

    http://www.redirect-checker.org - so I can see the redirects that are occurring, which often give a clue where to look

    and

    http://htaccess.madewithlove.be - to help me verify that my .htaccess is doing what I think it’s doing.

  • #3 / Nov 01, 2017 7:44pm

    Kubik101's avatar

    Kubik101

    155 posts

    Hi Derek.

    Thanks for clarifying that EE3 doesn’t do anything as far as redirecting.

    It made me look deeper.

    I did not develop this site originally so started to pick apart the templates.

    The following was in the header, which after removing solved the issue.

    [script]
        if ([removed].protocol == "https:") {
          [removed] = document.URL.replace("https://", "http://");
        }
    [/script]
  • #4 / Nov 01, 2017 7:52pm

    Derek Jones's avatar

    Derek Jones

    7176 posts

    What an odd thing, glad you found it!

  • #5 / Nov 01, 2017 7:53pm

    Kubik101's avatar

    Kubik101

    155 posts

    Yeh I have no idea why that code was there. Thanks again Derek, your answer helped rule out a couple of things. Cheers..!

ExpressionEngine News

#eecms, #events, #releases