How to Allow or Block IP address by Country Using .htaccess

Privacy invaders, Hackers, Competitors and others attack your site to lower your rank or try to cause inconvenience, so your business does not do well.

YouStable offers cPanel full version to the registered users so that you can get the most out of the features. cPanel offers a .htaccess file, and you have the power to block IP addresses.

First, we are going to show you, how you can access the cPanel and reach the .htaccess file.

Step 1: Log in to the cPanel by adding (domain.com/cpanel) and then hit enter. If you have forgotten the credentials, then open the email client associated with the YouStable account because we send a copy of the credentials to the registered email as well.

Step 2: In the search bar, type “file manager” and select the first result.

block IP address

Step 3: Double-click on the “public_html” and then it will take you one step closer to completing the process.

block IP address

Step 4: cPanel hides the file, so you have to click on the “settings” located on the same page at the top, and a pop-up appears on your screen.

Step 5: Click on “show hidden files” and then click on “save” to complete the process.

block IP address

Step 6: Now, select the .htaccess file, and right-mouse click to view more options, and click on “edit” it.

block IP address

Step 7: The confirmation pop-up shows up, and click on “edit” to proceed.

block IP address

Step 8: The .htaccess file is now editable.

block IP address

Step 9: Go to the IPDENY site to copy the IP address of specific country, and click on “download zone file” to download a text file, or you can click on “aggregated zone file” to view the IP address in another window.

How to Allow or Block IP address by Country Using .htaccess 1

Step 10: Okay, now you have to follow the order from the codes below.

block IP address
(order allow,

deny
deny from http://27.116.56.0/22

deny from http://58.147.128.0/19

allow from all)

The “Deny” will block the block IP address that you don’t want the traffic to come from it. The rest of the countries can view your site normally, but the mentioned IP address is blocked.

order allow,
deny deny from http://27.116.56.0/22
deny from http://58.147.128.0/19
allow from all

Now, if you want to allow specified traffic from selected countries, then you can use the below codes.

order deny,
allow deny from all 
allow from 211.35.214.13

The “allow from IP address” will allow the specific country only, while the rest of the world is blocked to access the site.

You may also like

Power up your business website with YouStable India’s affordable unlimited web hosting services and meet your online success! YouStable is not just a brand that provides hosting services to clients. The quality of services a customer gets from us is unparalleled and our clients know it.

Leave A Comment