Results 1 to 3 of 3

Thread: redirecting http to https using .htaccess cause a ERR_TOO_MANY_REDIRECT loop

  1. #1
    avid3935952 is offline Junior Member
    Join Date
    Jul 2023
    Posts
    2

    Default redirecting http to https using .htaccess cause a ERR_TOO_MANY_REDIRECT loop

    Hi guys, I'm having a huge problem with my .htaccess.

    If I try to change my htaccess into something like this:
    <IfModule mod_rewrite.c>
    RewriteEngine On

    # Ensure the HTTPS protocol
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
    </IfModule>

    I get an ERR_TOO_MANY_REDIRECT error (I haven curl -I -L to check from my CMD the problem and it does actually ends up in a loop).
    Is there a way to cleanly redirect http to https here?

    If I leave the things the way they are, it seems like that google search engine prioritize the http version instead of the https version, and also a quick check on https://httpstatus.io shows that the website redirect the one without www but not the http into https creating two identical pages (one http://www and the other https://www), I hope this make sense.

  2. #2
    alemoppo is offline AlterVista Staff
    Join Date
    Feb 2010
    Location
    IT
    Posts
    692

    Default

    Hello,

    Try this code:

    Code:
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{HTTPS} off
    RewriteRule .* https://www.pickdiff.com%{REQUEST_URI} [L,R=301]
    Bye!

  3. #3
    avid3935952 is offline Junior Member
    Join Date
    Jul 2023
    Posts
    2

    Default

    Quote Originally Posted by alemoppo View Post
    Hello,

    Try this code:

    Code:
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{HTTPS} off
    RewriteRule .* https://www.pickdiff.com%{REQUEST_URI} [L,R=301]
    Bye!
    That works beautifully, thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

SEO by vBSEO