Solve too many redirects error when using php in docker container in ecs

Viewed 201

I have a codeigniter project that i deployed into aws ecs cluster. i have 2 ec2 instances that i am using with a load balancer which later connects to a custom domain in route 53. In the codeigniter project i set the base variable in the config.php file to

$base  = "https://".$_SERVER['HTTP_HOST'];

When i use http i get a blocked:mixed-content error but when i use https i dont get an error when i use my custom domain with https. Now my error comes when i am trying to login into the application, i get the error of too many redirects. i tried to checkout around the internet and the examples i found where not clear for me.

so below is my .htaccess file content

    DirectoryIndex index.php

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)

RewriteRule ^(.*)$ index.php?/$1 [L]

i also created a docker image and i exposed the port 80 in the dockerfile, then i placed a port mapping of 80:80 tcp in the container in ecs

Then the load balancer has also a port 80 open to open web and then the custom domain

i want the application to use https throughout all the urls i am not sure where i have to make the changes so that i solve the error, thanks in advance

1 Answers

Could you please try following, written as per your shown samples. Please make sure to clear your browser cache before testing your URLs.

DirectoryIndex index.php

RewriteEngine ON
RewriteBase /
RewriteCond https !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !(index\.php|robots\.txt)/?$ [NC]
RewriteRule ^(.*)$ index.php?/$1 [L]
Related