How to Block Someone from Visiting Your Site

Article Posted by Expert Author: Jesse Schwarz  on 10/02/2013

Whether you're having trouble with a troll or just want to prevent any future attacks on your virtual home, it may become necessary to learn how to block certain IP addresses from gaining access to your web site at all. Whether you plan to do this temporarily or for the long term, you'll be happy to know that doing so is fairly easy.

.htaccess

This method can be applied if you own a blog and want to keep your useful comments available, but filter out those which serve no purpose to your readers. The .htaccess file controls how your site behaves, how secure it is and how well it performs.

The .htaccess file can actually be used in a number of ways, including redirecting visitors, providing customized error responses, and speeding up the response time for your site. But when you want to block people from visiting your spot on the web, you will want to create a file that deals with authentication and authorization.

If you have one site, using .htaccess can be a very efficient way to control who visits it. In order to do this, you will need to locate the IP addresses of those people who left spam comments on your site.

Locating the IP Addresses of Unwanted Visitors

You can locate the address of the offending visitor by finding the area of your blog which deals with the comments section. Every IP address of each commenter should be listed there. If your blog doesn't have this feature, you can try and check your server logs, which should list your visitors.

Once you've navigated to the offensive comment and have the IP address, it's time to block the individual.

Blocking

You can block your visitor by going to the Root directory of your web site. This can be done by opening your FTP program and logging into your web site. Once in the root directory - which is often the default directory when you log into a site's control panel with FTP - you will see a file called '.htaccess'. This will need to be downloaded to your computer.

Once downloaded, it's a good idea to create a copy of the .htaccess file so that the original can be restored if a mistake is made.

Then, open the file in Notepad or a similar program. Scrolling to the end of the document, add these lines:

<Limit GET POST PUT>
order allow,deny
allow from all
deny from xx.xx.xx.xx
< /Limit>

Then, just replace the exes above with the IP address of your unwanted visitor. To add more than one IP addres, simply copy the "deny from xx.xx.xx.xx" line as many times as needed, entering in each IP address to replace the exes.

Blocking by Country

There are many webmaster who wonder whether it's possible to block an entire country from visiting a web site. This is possible. And there are many free sites which offer lists of country-specific IP addresses. Once you have the IP addresses you want, you will have to go into your site's .htaccess file and deny them using the technique above.

Should You Place a Time Limit on Blocked IPs?

Generally, the rule is that not all of the people you block should be banned from your site forever. The reasoning for this is that not all IPs will point to the same individuals forever. And so if left long enough, you could end up blocking sites which are perfectly legitimate. Many times, a person who tries to visit a web site and gets denied is highly unlikely to revisit.

While blocking specific IP addresses from visiting your site may be a necessity from time to time, it's important to keep in mind that no solution may work 100%, or for the amount of time that you need it to. Checking online resources for available ways to block IPs will yield many options that can be executed when another option has failed.

At HostingAndBackup.com, we are dedicated to helping consumers answer important technical questions related to their websites.  We provide useful how-to articles such as this one that help you protect your online asset and make the most of your website on the worldwide web.


Article Posted In:  Tutorials  

Categories: TutorialsUseful TipsBest Web Hosting SitesWeb Hosting InformationOnline Computer BackupIndustry News & Articles