Block IP Addresses And Countries Using .htaccess - Knowledgebase

Block IP Addresses and Countries using .htaccess Support Portal » Knowledgebase » Viewing Article Print
  • 17-08-2018 10:44
    • cPanel
    • Block
    • IP Address
    • htaccess
Block IP Addresses and Countries using .htaccess
If you’re getting too much unwanted traffic from certain IP’s, a handy tool is the IP blocking feature of .htaccess file (click here for a tutorial on seeing which IP’s hit your site). This file is located in the public_html folder of your primary domain, and the primary folder of any subdomains and add on domains. Just add the following code to the top of your file:order allow,deny deny from 144.5.56.77deny from 12.34.23.107allow from allYou can also do the reverse, and allow only specific IP’s to be allowed on your site:order deny,allowdeny from allallow from 211.35.214.13What if the unwanted visitor is from a different country and keeps changing their IP? Provided your website isn’t intended for visitors from that country, you can easily use the GeoIP tool to block that country. Just add the below code to the top of your .htaccess file.GeoIPEnable On# Add countries you wish to deny hereSetEnvIf GEOIP_COUNTRY_CODE CO DenyCountrySetEnvIf GEOIP_COUNTRY_CODE EG DenyCountrySetEnvIf GEOIP_COUNTRY_CODE HI DenyCountryAllow from allDeny from env=DenyCountryYou can also do the opposite and only allow specific countries to access your website. This is a great proactive security measure if, for example, you only intend to have Australian clients or visitors to your site.GeoIPEnable On# Put countries to allow hereSetEnvIf GEOIP_COUNTRY_CODE AU AllowCountrySetEnvIf GEOIP_COUNTRY_CODE NZ AllowCountryDeny from allAllow from env=AllowCountryA list of all country codes can be found bellow or at their original source here:http://dev.maxmind.com/geoip/legacy/codes/iso3166/
Thank you for your feedback on this article. Share via

Related Articles

    • 28-03-2018 10:33
    How to Block IP Addresses or Countries to your Website Using .htaccess
    • 22-03-2018 11:29
    How to find IP addresses hitting your website and block them in cPanel
    • 17-08-2018 10:23
    Block All Access to your Website Using .htaccess
© Crucial

Từ khóa » Htaccess Block Russian Ip