Apache.htaccess convert http uri to https causing redirect loop

I know this question has been asked a thousand times, but I cannot find the answer.

We have a website hosted in 123-reg web hosting package (no access to http config files). I have added ssl to the site and the certificate works when it requests to use https directly.

The problem occurs when I try to redirect everything from http to https using the .htaccess file.

First I tried the SERVER_PORT variable in the condition:

RewriteEngine On
RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.co.uk/$1/ [R=301,L]

      

This does not work as the https redirect request also uses port 80 (I am currently requesting this with 123-reg). The condition is always met and calls the redirect loop.

Next, I tried the HTTPS variable: RewriteEngine On RewriteBase /

RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://example.co.uk/$1/ [R=301,L]

      

This condition is always met because the variable is never included (and causes a redirect loop). I wonder if it has something to do with port no = 80 for https.

I found two server variables, SSL and HTTP_X_FORWARDED_SSL, which change from "" to 1, but only when I delete the .htaccess file and request http or https directly.

If I try to use the SSL or HTTP_X_FORWARDED_SSL variables in RewriteCond it triggers a redirect loop.

I can't see the variables while the redirect loop is in progress, so I don't know if they change during the redirect.


edit:

I found the answer. I used:

RewriteCond %{SSL} !1

      

which should be:

RewriteCond %{ENV:SSL} !1

      

+2
redirect ssl apache .htaccess


source to share


No one has answered this question yet

See similar questions:

3
.htaccess file does not redirect http: // www. https: // www

or similar:

3
redirect ssl to non ssl
2
How to redirect from www to https www with htacces?
2
https to http redirect
1
.htaccess redirects when file doesn't exist
1
Htaccess url redirect works for http not all https
1
Redirect from http to https not working
0
Redirect from blog.domain.org to domain.com using htaccess
0
404 in two htaccess in root domain and attached file
0
htaccess 301 redirect in apache 2.4 doesn't work
-3
Redirect 301.htaccess not working



All Articles
Loading...
X
Show
Funny
Dev
Pics