Hi there
I’m having an issue whith redirect loop issue on browsers only when I try to redirect US to the full domain so for example domain.com. It works perfectly fine if I redirect it to another domain or use subfolder on main domain.
So I’m using the following htacces code
RewriteEngine on
RewriteOptions inherit
RewriteCond %{HTTP_HOST} domain/ com [NC]
RewriteCond %{SERVER_PORT} 80RewriteRule ^(.*)$ https:// domain/ com/$1 [R,L]
DirectoryIndex index.php
So my main traffic is from the US so I want them to stay on the domain only so not to a subfolder or any other domain, and for some countries I redirect them to a subfolder. To do this I’m using a php code. Note: I’ve tried also doing other coding via htaccess to do the following but I always had same redirect loop issue doing that also.
<?php $country_code = $_SERVER["HTTP_CF_IPCOUNTRY"]; if ($country_code == 'US') { header("HTTP/1.1 301 Moved Permanently"); header("Location: https:// domain/com"); die(); } else if ($country_code == 'LU') { header("HTTP/1.1 301 Moved Permanently"); header("Location: https:// domain/com/LU/"); die(); } else if ($country_code == 'MA') { header("HTTP/1.1 301 Moved Permanently"); header("Location: https:// domain/com/MA/"); die(); } else header("HTTP/1.1 301 Moved Permanently"); header("Location: https:// google.com/"); die(); } ?>
What I want to achieve is that I only want the countries to get on my website and all other countries to google since I don’t want them to see my website at all. Issue I’m facing is that it won’t work if I redirect them back to the domain they are already on… so person 1 types in domain.com wich is from US and gets redirect error on his screen… while for the others it works perfectly fine since they are being redirected to the subfolder on that domain.
Can someone tell me what is causing this issue? (I’m using a vps centos/cpanel)