
If you want to allow or restrict users from a specific country, you can do it with .htaccess. We are going to share the easiest methods to allow or restrict visitors from the country you want.
With some minor changes in the .htaccess file, you can allow or restrict visitors from any country. It is all in your hand to choose to what country you want to show your website.
But before we go, Here is why you would want to allow or restrict visitors from specific countries.
Reasons for allowing or blocking visitors from specific countries
There are various reasons to allow or block visitors from different countries. Here are a few of them to have a look:
You don’t wish to provide services: You must have encountered some issues from people of specific countries. If you do not wish to provide them any service, just block the country.
You cannot ship the products: Suppose you are running an eCommerce store. If you cannot deliver the products to any country, there is no point in getting the traffic (hope) from there.
Country-related Content: If you are focusing on your specific country for your website, you can just allow the traffic from the same country. If the content is not relatable to other countries, you can block them all.
And Many More…
How to allow or restrict visitors from specific countries on WordPress
You are going to see how to allow or block visitors from specific countries. Before we begin, it is recommended to take a complete backup of your WordPress website.
As we are going to use the .htaccess file, you must need to have access to the File Manager of your site. Here are the simple steps that you can follow:
Step 1: Get the IP address of the country
This is the first step in allowing or restricting the visitors on your website. You need to get the IP address of any country you wish to allow or restrict.
The IP of a country will help us in providing information about the country we want to allow or restrict visitors. Follow these steps to get the IP address of as many countries:
- Firstly, visit the homepage of IP2Location Visitor Blocker page.
- From the drop-down menu, select the countries you want to restrict or allow.
- Select the IP Version as IPv4
- From the Output format, Select the version as the one from Apache on your server. Also, select Allow if you wish to allow from those countries & deny if you wish to restrict.
- Click on Download, this will download the ACL file to your local system.
This is how you can generate the IP address of countries you wish to allow or restrict the visitors. There are various other platforms available online to generate the IP address.
You can go with any of the methods you like for generating the Countries’ IP Address. Once done, We move ahead to the next step for allowing or restricting the visitors from specific countries.
Step 2: Add the IP Address of countries in the .htaccess file
Now, All we have to do is add those countries’ IP addresses in our .htaccess file. This will modify the functionality of WordPress & it will change the country’s access accordingly.
To add the IP address in the .htaccess file, you need to follow the steps below:
- Open the File Manager / FTP Client of your choice. You can directly go to cPanel and click on File Manager if you have not experienced it yet.
- Once you have access to the files, click on public_html folder of your website
- Now, right-click on .htacess file & select the Edit option from the menu. In some cases, (.) dotfiles are hidden by default. You can change the settings from View option on top.
- When you are in Edit mode for .htaccess file, also open the file that you downloaded on your system
- Paste the text from the downloaded file into your .htacess file in the end.
- Once done, Save the changes in your .htaccess file.
- Close the file manager & open the Website, Clear Cache if you are using cache.
You can even use the WordPress dashboard to edit the .htaccess file. In order to do so, all you have to do is install a suitable plugin for that.
If you want to check if any country can see your website or not, It is difficult, right? No. You can check the same by calling your friend living in that country and ask him to open the website😁.
Well, That’s it. This is how you could add the ACL in your .htaccess file. We hope that you didn’t mess up. It was pretty simple, right?
Conclusion
That was quick. Have you seen such an easy task to block the whole country from accessing your website? Guess what, We did it. We hope that you have finally allowed or restrict countries of your choice to the website.
How was your experience while blocking any country? And, How did you manage to check if the country is really blocked from visiting on your website? We are interested in hearing them all, share your experience with us.
Happy Choosing 😜 !!