1

My problem is specific because site redirects are a bit complicated in the www folder with php codes

index.php

 <?
header("Location:https://www.example.org/kods_bird/uye/?fsx=@");
?>

this redirect exists and the kods bird folder has the same redirect

my .htaccess, Located in the www folder

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Why is ERR_TOO_MANY_REDIRECTS error?

Which solution am I looking for?

url request:http://www.example.org%{REQUEST_URI}
url redirect:https://www.example.org%{REQUEST_URI}
Z.Kirik
  • 121
  • 1
  • 1
  • 10

1 Answers1

0

So there was logical issue which caused looping inside rules.

So try this fix:

# rewrite non https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# if https but without www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


let's analyze 1st situation:

http://www.example.org%{REQUEST_URI}

will be handled by first rule (https off) which will redirect to with https version:

https://www.example.org%{REQUEST_URI}


let's analyze 2nd situation:

http://example.org%{REQUEST_URI}

will be handled by first rule (https off) which will redirect to with https version:

https://example.org%{REQUEST_URI}

and after will be handled by second rule which will add www. as prefix:

https://www.example.org%{REQUEST_URI}
num8er
  • 18,604
  • 3
  • 43
  • 57
  • seems like it happens by php scripts, I hope it's all from .htaccess? or You've other directives which does global rewrite? – num8er Apr 21 '20 at 12:22
  • @Z.Kirik try to remove from kod_bird folder that rules or update htaccess in that folder too – num8er Apr 21 '20 at 12:23
  • I examined the $ _SERVER array with PHP, anyway when the protocol is https No HTTPS parameter inside array $ _SERVER – Z.Kirik Apr 21 '20 at 13:01
  • @Z.Kirik well it means that mod php does not pass protocol attribute which may happen when AllowOverride is disabled in virtual host configs https://stackoverflow.com/questions/17550223/set-an-environment-variable-in-htaccess-and-retrieve-it-in-php – num8er Apr 21 '20 at 13:04
  • so You can fix in php level to not check http or need to fix in apache configs – num8er Apr 21 '20 at 13:06
  • Can we say that the https redirect fails because apache does not allow changes? – Z.Kirik Apr 21 '20 at 13:38
  • @Z.Kirik 50/50 I don’t have full picture. app is laravel based or something custom? why not disable that custom stuff to not redirect? since we are doing already with apache – num8er Apr 21 '20 at 13:40