We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

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

News and General

Kubik101's avatar
Kubik101
155 posts
7 years ago
Kubik101's avatar Kubik101

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>
       
Derek Jones's avatar
Derek Jones
7,561 posts
7 years ago
Derek Jones's avatar Derek Jones

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.

       
Kubik101's avatar
Kubik101
155 posts
7 years ago
Kubik101's avatar Kubik101

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]
       
Derek Jones's avatar
Derek Jones
7,561 posts
7 years ago
Derek Jones's avatar Derek Jones

What an odd thing, glad you found it!

       
Kubik101's avatar
Kubik101
155 posts
7 years ago
Kubik101's avatar Kubik101

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

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.