For Linux Hosting
Learn how to use an .htaccess file to deny certain IP addresses from accessing your website.
Blocking an IP address may be necessary if you are aware of that IP addresses attempting to abuse or attack your website.
Create a new text file and name it .htaccess.
Please note: Use a basic text editor such as "Notepad" in Windows, "TextEdit" for Mac OS X, or "vim" for Linux. If you already have an .htaccess file on your web space, you can download it first and then edit it.
Enter the following code in the .htaccess file, replacing 18.104.22.168, with the IP address you want to block.
<Limit GET POST> order allow,deny allow from all deny from 22.214.171.124 </Limit>
- Line 1: Specify which HTTP methods are to be restricted.
- Line 2: Rules that allow connections should be processed before rules for denying connections
- Line 3: All connections should be allowed (unless specified otherwise)
- Line 4: Exceptions to the rule in the line above
- Line 5: End of the section
You can also prohibit access to multiple IP addresses or entire IP address ranges, as shown below:
<Limit GET POST> order allow,deny allow from all #Multiple single IPs deny from 126.96.36.199 deny from 188.8.131.52 deny from 184.108.40.206 #Entire IP range deny from 220.127.116.11/21 </Limit>
Upload the .htaccess file to your web space. The parameters set in the .htaccess will apply to all subdirectories.
To prohibit connections to the entire web space, save the file in the main folder. If you only want to prohibit access for a specific web page, save the file in the subfolder that contains the web page.
The settings will take effect immediately once uploaded.