Search code examples
wordpresshttp-redirectblockip-address

Restrict/Change content according to Country (IP Address)


a = worldwide access b = only one specific country

I have a wordpress website:domain.com, that includes 1 page:domain.com/a that is relevant for all countries worldwide except for 1 country (example: Italy). I want to block italy from domain.com/a and automatically show them the other version of this page domain.com/b.

My idea: I prefer not to make a subdomain so I just duplicated the domain.com/a page, called the version for italy domain.com/b.

Now, when clicking on the button in menu bar that would lead to domain.com/a how can I make sure this button will take visitors from Italy to domain.com/b and block them from domain.com/a ?

I see in many cases plugins ask to buy MaxMind database, I would prefer to find a free solution.

I found this post and I want to do exactly the same: How show content depending on country ip address. they found a solution but for Kirby users only. How can I apply the same strategy for my wordpress site?

Thank you


Solution

  • Well, if you want to make that decision based on the IP address you will most probably need some kind of service like MaxMind (they got a free database, too).

    But IP addresses change and you might probably "hit" the false visitors with your switch.

    You could also use a multilingual WordPress solution, which might fit better what you want to do. There are several plugins which can change pages or languages based on the browser language. Google can help you or you could start here: How to easily create a Multilingual WordPress Site

    If you could give some further information on what and why you want to switch pages, there might be other, better solutions.