We have a WP website in an EC2 instance. Over that, we have a CloudFront distribution which is serving the DNS requests. At times we face the website error - redirected too many times. While checking the server logs, we find that CF requests are given response as 301 by the server. Sometimes the website works, but gtmetrix.com fails saying Visiting the page has resulted in an endless chain of redirects.
My .htaccess looks like the below. And I have a behaviour setting in CF asking to reroute http requests to https.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
#RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
#RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
Not sure is this the actual problem. Any guidance would be really helpful.