Redirect domain.com to domain.com/a for IPs from country A

Hello and wondering how to redirect correctly for https://domain.com to https://domain.com/a if users browse from country A.

Appreciate for any detailed instructions such as which field, operator, value, redirect type, url to redirect to, code 30x and Preserve query string or not.

Thanks,

Hi,

Please see this answer to a similar topic.

1 Like

Thank you for your reply but I was not able to get it worked. What would be the correct rules for:

Appreciate any help.

Please post exactly what you tried, and what didn’t work. (Too many redirects? Didn’t detect country properly? etc.) Post screenshots of any error messages.

I tried this and it gave “redirect to many times” error:
(http.host eq “domain.com” and ip.geoip.country eq “US”)
then static redirect to https://domain.com/us (not Preserve query string)

I tried this (with /) and it did not redirect:
(http.host eq “domain.com/” and ip.geoip.country eq “US”)
then static redirect to https://domain.com/us (not Preserve query string)

Pls help

The hostname (http.host) does not include “/”, which is a path element. So the first expression is right. To avoid the redirect loop you need to exclude requests that have already been redirected, as shown in the example I gave you.

and not starts_with(http.request.uri.path, "/us")

Thank you! So here is the settings I got:
(http.host eq “domain.com” and not starts_with(http.request.uri.path, “/us”) and ip.geoip.country eq “US”) then static redirect to 'https://domain.com/us
It seems to work but then any visit to 'domain.com/page other than /us redirected to /us. Is there any other settings that can help redirect as above but still able to visit any other page on 'domain.com?

Do you want visits to example.com/some-page to be redirected for US visitors to example.com/us/some-page?

Or do you want only the homepage to redirect for US visitors?

I want only the homepage redirected to /us for us visitors and same for any other countries. And visitors (anywhere) can visit any page or 'sub.domain.com, for example US visitors when visiting the homepage will be redirected to 'domain.com/us but if they are able visit 'domain.com/any-page.
Thanks so much,

Change the initial condition from

http.host eq "domain.com"

to

http.request.full_uri eq "https://domain.com/"

That should make the Redirect Rule apply only to the homepage.

BOOM!!! You’re gold and thank you so much!!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.