How to block unwanted traffic to your website from specific IP’s
Malicious or unwanted traffic to your website can be blocked by adding a snippet of code to the .htaccess file within your site content.
It’s possible to block traffic from specific IP’s or a range of IP’s from visiting your website. Even traffic from entire countries can be blocked.
Note: Cloudbric, the security service offered by us, provides a dashboard to easily block IP’s or countries.
No coding or experience is required – just follow the steps below.
Block IP’s using .htaccess
The .htaccess file is located in the public_html directory of your website content. If you only want to block access to certain parts of your site, you can create a new .htaccess file and upload it to the relevant subdirectory.
This file can be accessed and edited in various ways, including FTP and SSH. Here we will access it via the konsoleH File Manager:
- Browse to konsoleH and log in (Admin or Domain level)
- If Admin level: Select or search for a domain name in the Hosting Services tab
- Click Manage Services from the left-hand menu
- Select File Manager. The files within the public_html folder are immediately visible – these are website files and includes the .htacess file that governs your whole site.
- Click .htaccess in your file list, then click Edit from the right-hand menu.
- Insert the following code snippet at the top or bottom of any other code that is already in the text file, replacing the sample IP’s with those that you want to be blocked. Any number of IP’s can be listed. Click Save changes
order allow,deny deny from 123.456.789.01 deny from 12.123.456.78 deny from 234.56.789.123 allow from all
Note: Should you wish to block traffic to your website from a particular region, you can make use of IP2Location API. More information on this PHP module can be found here.