How to Block a Country from Accessing Your Website

I’ve already talked about how to block an IP address.

In this post, we’ll see how to block a country from accessing your website. Let’s get started.


If you’re a Cloudflare user, then follow the below steps:

Sign into your Cloudflare account and then choose your website.

Hit Firewall > Firewall Rules.

Click on “Create a Firewall rule” button.

Give a name for the rule and then select “Country” from the first drop-down list.

Make sure “equals” is selected in the second drop-down list and choose the country you want to block from the third drop-down list.

Rule to block a country

In the drop-down list under “Choose an action,” make sure “Block” is selected.

Hit the “Deploy” button.


It may block known bots from accessing your site and here’s how you can avoid that:

Create a new firewall rule like the screenshot below:

Rule to allow known bots

Make sure this rule stays above the rule that you’ve created earlier.

Wordfence Premium

If you’re a Wordfence premium user, then you can use its inbuilt option to block the country you prefer.

Remember that if you block a country using Wordfence, not only the users but the bots from that country will also be blocked.


If you’re a Sucuri user, then follow the below steps:

Sign into your Sucuri account.

Hit the site URL > Access Control. Now, you can see “Geo Blocking.” Hit it.

Remember that you need to check the first check box if you want to block a country from viewing your site and the second check box if you wish to let a country to see your website, but not allow them purchase, login, comment, and register.

Geo Blocking screen

Find the country you want to block and then check the first check box beside it. Hit the “Save” button.

See: How to Schedule Posts on WordPress


Note: I don’t recommend this method since it can affect your site’s performance negatively.

Go to this URL. Scroll down and then choose your country from the first drop-down list at the bottom.

Choose the IP version (IPv4 or IPv6, depending on your need) and output format (Apache 2.1 – 2.3 .htaccess deny or Apache 2.4 .htaccess deny, depending on your requirement).

Hit the “Download” button.

Download button

Now, copy the contents of the downloaded text file.

Open your site’s .htaccess file and paste it in there. Make sure to save the changes.

I hope that this guide is useful to you. Like this guide? Please share it with your friends.

Disclaimer: This post may contain affiliate links which means I will receive the commission (at no additional cost to you) when you purchase the product via my links. Thanks for your support.

Also see:

How to Delete Posts on WordPress

How to Duplicate Posts on WordPress

Scroll to Top