Geoip redirect in htaccess causes loop

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Berrymanrgb

Thread Starter
Joined
Oct 3, 2018
Messages
1
Hi,

I am trying to set up simple redirections to send visitors to my website to the correct country page.

The Apache GeoIP module is installed and enabled.

In my htaccess file I added the redirects as suggested in the documentation but just get stuck in a redirect loop when I test it.

Code:
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^GB$
RewriteRule ^(.*)$ https://uk.beta.mydomain.com/$1 [R=302,L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^DE$
RewriteRule ^(.*)$ https://de.beta.mydomain.com/$1 [R=302,L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^ES$
RewriteRule ^(.*)$ https://es.beta.mydomain.com/$1 [R=302,L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^(.*)$ https://us.beta.mydomain.com/$1 [R=302,L]

# BEGIN WordPress

RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

# END WordPress
I then tried adding the following line at the top:

Code:
RewriteCond %{HTTP_HOST} !^(uk|us|de|es)\.beta\.mydomain\.com$ [NC]
Now the top redirect works but ones below still loop (they work if I comment out the redirects above).

Am I missing something simple here? Only used to setting up page redirects normally so a bit out of my depth! Cheers.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top