# Geolocation redirection for external published DNS

**URL:** <https://community.f5.com/t/geolocation-redirection-for-external-published-dns/50547>\
**Category:** Technical Forums\
**Tags:** big-ip, big-ip-dns, application-delivery\
**Created:** [November 3, 2021, 9:28am UTC](https://community.f5.com/t/geolocation-redirection-for-external-published-dns/50547 "2021-11-03T09:28:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![asabado](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@asabado](https://community.f5.com/u/asabado)\
**Post date:** [November 3, 2021, 9:28am UTC](https://community.f5.com/t/geolocation-redirection-for-external-published-dns/50547/1 "2021-11-03T09:28:20Z")

</div>

I received a request to set up a redirection in the bigip depending on where the traffic is coming from. Basically when a customer accesses [finder.abc.com](http://finder.abc.com)(sample) from Spain, it gets redirected to [https://www.abc.com/es-es/home/servicepoints.html](https://www.abc.com/es-es/home/servicepoints.html). or if the access comes from SE, it goes to [https://www.abc.com/se-se/home/servicepoints.html](https://www.abc.com/se-se/home/servicepoints.html). or if the Geolocation is unknown it gets redirected to home.

Is this achievable in F5 bigip? the challenge is that the requests would be coming from external access so assuming that anybody in Spain accesses the URL, then it redirects accordingly.

Appreciate any help.

---

<div class="post-metadata">

**Author:** ![spalande](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/spalande/32/10043_2.png) [@spalande](https://community.f5.com/u/spalande)\
**Post date:** [November 3, 2021, 2:14pm UTC](https://community.f5.com/t/geolocation-redirection-for-external-published-dns/50547/2 "2021-11-03T14:14:37Z")

</div>

You can use something like below

```tcl
when HTTP_REQUEST {
	switch -glob [whereis [IP::client_addr]country] {
             "ES" 
		{
                       HTTP::respond 301 Location "https://www.abc.com/es-es/home/servicepoints.html"
		} 
		"CH"
		{
		      HTTP::respond 301 Location "https://www.abc.com/se-se/home/servicepoints.html"
		}
		default {
		       HTTP::respond 301 Location "https://www.abc.com/home"
		}
	}
}

```

Please check below for selecting country code in iRule accordingly.

[https://support.f5.com/csp/article/K4034](https://support.f5.com/csp/article/K4034)

---

<div class="post-metadata">

**Author:** ![asabado](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@asabado](https://community.f5.com/u/asabado)\
**Post date:** [November 3, 2021, 3:44pm UTC](https://community.f5.com/t/geolocation-redirection-for-external-published-dns/50547/3 "2021-11-03T15:44:27Z")

</div>

Thanks SanjayP. Pardon my ignorance but this will be implemented in GTM I assume? Or can it be done at LTM level? Do I need to define the countries anywhere first? Get Outlook for Android\<\>\>

---

<div class="post-metadata">

**Author:** ![spalande](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/spalande/32/10043_2.png) [@spalande](https://community.f5.com/u/spalande)\
**Post date:** [November 3, 2021, 3:48pm UTC](https://community.f5.com/t/geolocation-redirection-for-external-published-dns/50547/4 "2021-11-03T15:48:02Z")

</div>

this will be in LTM. You just use countrycode in iRule as mentioned above.

e.g. ES - Spain, CH - Switzerland

---

<div class="post-metadata">

**Author:** ![spalande](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/spalande/32/10043_2.png) [@spalande](https://community.f5.com/u/spalande)\
**Post date:** [November 3, 2021, 3:50pm UTC](https://community.f5.com/t/geolocation-redirection-for-external-published-dns/50547/5 "2021-11-03T15:50:39Z")

</div>

I see you were using SE for Sweden. So iRule would be following

```tcl
when HTTP_REQUEST {
	switch -glob [whereis [IP::client_addr]country] {
             "ES" 
		{
                        HTTP::respond 301 Location "https://www.abc.com/es-es/home/servicepoints.html"
		} 
		"SE"
		{
		       HTTP::respond 301 Location "https://www.abc.com/se-se/home/servicepoints.html"
		}
		default {
		        HTTP::respond 301 Location "https://www.abc.com/home"
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![asabado](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@asabado](https://community.f5.com/u/asabado)\
**Post date:** [November 4, 2021, 9:05am UTC](https://community.f5.com/t/geolocation-redirection-for-external-published-dns/50547/6 "2021-11-04T09:05:49Z")

</div>

Thanks SanjayP, I did try out the irules but it didn’t seem to work.. ☹

---

<div class="post-metadata">

**Author:** ![spalande](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/spalande/32/10043_2.png) [@spalande](https://community.f5.com/u/spalande)\
**Post date:** [November 4, 2021, 9:45am UTC](https://community.f5.com/t/geolocation-redirection-for-external-published-dns/50547/7 "2021-11-04T09:45:23Z")

</div>

F5 has inbuilt gelocation database so this should work. I see there was 1 typo in iRule

(space between [IP::client\_addr] country).

Please correct below and also enable some logging and provide the log output if still not working.

```tcl
when HTTP_REQUEST { 
	switch -glob [whereis [IP::client_addr] country] {
             "ES" 
		{     
                        log local0. "ES IP match: [IP::client_addr]"
                        HTTP::respond 301 Location "https://www.abc.com/es-es/home/servicepoints.html"
		} 
		"SE"
		{      
                       log local0. "SE IP match: [IP::client_addr]"
		       HTTP::respond 301 Location "https://www.abc.com/se-se/home/servicepoints.html"
		}
		default {
                        log local0. "no match: [IP::client_addr]"
		        HTTP::respond 301 Location "https://www.abc.com/home"
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![asabado](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@asabado](https://community.f5.com/u/asabado)\
**Post date:** [November 12, 2021, 12:00pm UTC](https://community.f5.com/t/geolocation-redirection-for-external-published-dns/50547/8 "2021-11-12T12:00:04Z")

</div>

Hi SanjayP, thank you for your response. I have tried to modify it based on above given syntax but still doesn’t work.

I’m getting site can’t be reached and unexpectedly closed the connection. below is the actual link i created.

**[qsfvcuuqzdxxvdw-dhlfinder-redirection-test.dhl.com](http://qsfvcuuqzdxxvdw-dhlfinder-redirection-test.dhl.com)**

---

<div class="post-metadata">

**Author:** ![spalande](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/spalande/32/10043_2.png) [@spalande](https://community.f5.com/u/spalande)\
**Post date:** [November 12, 2021, 12:43pm UTC](https://community.f5.com/t/geolocation-redirection-for-external-published-dns/50547/9 "2021-11-12T12:43:39Z")

</div>

This isn’t issue because of this iRule. Something else is causing the issue. Capture Tcpdump and analyse what is causing the reset.
