From http to https - htaccess and URL rewrite - Too many redirect error

I have a site with the following working code in .htaccess to get friendly URLs:

RewriteEngine On
RewriteRule ^([^_]*)_([^_]*)\.html$ /?s=scheda&id=$1&slug=$2 [L]
RewriteRule ^([^/]*)\.html$ /?s=$1 [L]

Since I installed a SSL certificate, I need to update my .htaccess to redirect http contents to https. I found this code:

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

And I tried to add it to my .htaccess:

RewriteEngine On
RewriteRule ^([^_]*)_([^_]*)\.html$ /?s=scheda&id=$1&slug=$2 [L]
RewriteRule ^([^/]*)\.html$ /?s=$1 [L]

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

but I get a "Too many redirect problem" error.

What's wrong?

Thanks a lot.

1 answer

  • answered 2018-01-12 10:33 Eugène Adell

    This error indicates you are looping, and I can see only one rule that could loop :

    RewriteRule ^([^/]*)\.html$ /?s=$1 [L]
    

    This redirects a.html to ?s=a.html which matches this same rule.

    But it shouldn't work in http too. Can you confirm ?