This article will demonstrate various ways to block unwanted site visitors via your .htaccess file. This will allow you to block things such as specific IP ranges, or even bots that may be causing issues with your site by not adhering to your robots.txt rules. Follow along below as we describe different ways to block these unwanted visitors.
To be able to place the blocking code, you will need to know how to edit your .htaccess file, which is found in your cPanel File Manager. Once you have accessed the .htaccess file and opened the editor, you can then decide on which method you will use to block the visitors. Simply paste the appropriate code into the top of the .htaccess file to keep out the unwanted visitor.
If you know a visitor's IP address, you can block that single IP address with a simply line of code known as a deny. Below is an example of denying access to an IP address of 111.222.111.222.
You can also block an entire range of IP addresses. If you leave off the last set of numbers of the IP address (known as an octet), this will block the entire range of that octet. For example, 111.222.111.1 - 111.222.111.255 Below is a sample of the code you would place in your .htaccess file to do this.
This next method is a bit more complex. It first requires that the RewriteEngine be activated, then evaluates the user-agent string of the incoming request of the visitor. In the sample code, if the words Baiduspider or Yandex (which are bots for Chinese and Russian search engines, respectively) is in the user-agent, it activates the RewriteRule line of code, in which we send them a 403 (access denied) code.
Email: | support@WebHostingHub.com | Ticket: | Submit a Support Ticket |
---|---|---|---|
Call: |
877-595-4HUB (4482) 757-416-6627 (Intl.) |
Chat: | Click To Chat Now |
We value your feedback!
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
new! - Enter your name and email address above and we will post your feedback in the comments on this page!