1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Geoip redirect in htaccess causes loop

Discussion in 'Web Design & Development' started by Berrymanrgb, Oct 3, 2018.

Thread Status:
Not open for further replies.
  1. Berrymanrgb

    Berrymanrgb Thread Starter

    Oct 3, 2018

    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.

    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:

    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.
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 733,556 other people just like you!

Similar Threads - Geoip redirect htaccess
  1. Amy.26
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1217318

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice