Recently I have installed the ssl certificate for our domain. And as part of https secure redirection, changed the htaccess to redirect to https. It works fine with the home page. But when I am login as a user or as an admin, the redirection fails and getting a message like too many redirects and page loading is failed due to redirect looping back and forth between https and http. Please help me to solve this issue.
Please find the current htaccess file that I am using
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.flatparty.com/$1 [R,L]
RewriteRule ^(blog)($|/) - [L]
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
When I access https://www.flatparty.com it works fine. But once I logged in gets the redirection issue.
Finally I got the fix for the issue !!. It was not the issue with .htaccess content, it was the issue with the server code. The following code was the reason for the redirect loop issue.
$host = $_SERVER['HTTP_HOST'];
$request_uri = $_SERVER['REQUEST_URI'];
$good_url = "http://" . $host . $request_uri;
header("HTTP/1.1 301 Moved Permanently");
header("Location: $good_url");
The .htaccess code is working fine and whenever htaccess redirects url to https and the above mentioned code gets redirected to http and eventually it leads to an infinite loop and request will never completes.
Thanks for the help and suggestions.