≡ Menu

[How-To Guide] Block Visitors From Specific IP Address Using .htaccess

Already I have share few guides on .htaccess. Here is a quick recap:

How to Create .htaccess for WordPress Blog

How to Edit .htaccess File

How to Avoid Spam Comment in WordPress Blog Using .htaccess

Blocking a specific visitor from specific IP is pretty easy and you can do it in easy step, just follow this how to guide and block a specific user in few steps.

Step1: Log-in into cPanel by typing URL (mentioned below) and click on “File Manager” as shown below:

http://www.domainname.com/cpanel (replace domain name by your own domain)


Step2: When you click on “File Manager” (in step 1), it open a new window (as shown below), i.e, root directory of your domain.


Step3: Now select .htaccess file and click on “Edit” option in navigation menu as shown below:


Step4: After clicking on “Edit” option in navigation menu, it open a new window as shown below:


Step5: Now copy this code and paste this code (in step 4) in .htaccess file.

order allow,deny
allow from all
deny from xx.xxx.xx.xxx

Here xx.xxx.xx.xxx is the IP address of the person you want to block. You can replace this with your visitor IP address.

Step6: When you paste this code (code you get in step5) click on “Save” button as shown below:


Step7: Congratulations, you have successfully block visitors from specific IP address using .htaccess

If you have any query do let me know in comment section and don’t forget to like on Facebook so that you don’t miss any .htaccess tutorial.

If you like this post and find informative, don’t forget to share it on social networking sites.

{ 4 comments… add one }
  • Useful tip but one problem is when you accidentally block your own IP, My internet connection uses a dynamic IP and auto generates a random IP address, every time I connect to the internet. So in these cases, it might not work

    But when you want to block spammers from a specific region or country, this will help.

    • Thanks for Stopping and Commenting here
      Yaa for dynamic IP, there are issues and advised no to edit .htaccess but for spammers it is pretty useful

  • its better to download the htacces file, save a copy and edit it, upload.

    Thanks for the tutorial.

    • Yaa Anish, its better to have a back-up of .htaccess before editing it otherwise you mess up all the things

Leave a Comment