{"id":438,"date":"2012-08-02T17:46:38","date_gmt":"2012-08-02T17:46:38","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/2012\/08\/02\/block-country-ips\/"},"modified":"2023-07-03T11:04:11","modified_gmt":"2023-07-03T15:04:11","slug":"block-country-ips","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/","title":{"rendered":"Block Country IPs From Your Site Using htaccess"},"content":{"rendered":"<p>cPanel has an <strong>IP blocking<\/strong> mechanism to help you secure your site from individuals who you deem suspicious or malicious. This works fine for a single IP or even a handful. It is not advisable however, if you want to <strong>block an entire country using your .htaccess file<\/strong>.<\/p>\n<p>People may want to block a country for different reasons. Some countries are more notorious for having hackers or spammers. Other people want to block a country simply because they do not do business with them. In any case, you can set the code within the htaccess file to <strong>block the IP ranges of certain countries<\/strong>. Follow the instructions below to perform this task.<\/p>\n<h2>Blocking a Country From Accessing Your Site via the .htaccess File<\/h2>\n<ol class=\"article_list\">\n<li>First you will need to collect the data. You want to find a reliable list of IPs for the country you want to block. Doing a search, we find that you can get your deny list generated at IP2Location\u2019s free <a href=\"https:\/\/www.ip2location.com\/free\/visitor-blocker\" target=\"_blank\" rel=\"nofollow noopener\">visitor-blocker generator<\/a>. Using this tool will let you download a text file with the code needed to block a country. In our example, we randomly chose Algeria. The output format we chose is the <i>Apache .htaccess deny<\/i>. Follow the steps to download your file.\n<div class=\"alert alert-info\" role=\"alert\" style=\"margin-top:10px;\"><strong>Note:<\/strong> If you cannot find the IP address to a specific set of countries, sites like <a href=\"https:\/\/countryipblocks.net\/\" target=\"_blank\" rel=\"nofollow noopener\">countryipblocks.net<\/a> offer this data for a fee.<\/div>\n<\/li>\n<li>Open your file in the text editor of your choice and highlight and copy the information in the file.<\/li>\n<li>Next, <a href=\"\/support\/edu\/cpanel\/how-to-log-into-cpanel\/\">log into your cPanel<\/a> to access the .htaccess file.<\/li>\n<li>Find the <i>Files <\/i> category and click on the <b>File Manager<\/b> icon.<br>\n<img decoding=\"async\" width=\"964\" height=\"196\" src=\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2012\/03\/cpanel_file-manager-paper-lantern.png\" class=\"optimized-lcp-image\" alt=\"\" loading=\"eager\" fetchpriority=\"high\" sizes=\"(max-width: 768px) 100vw, 768px\"><\/li>\n<li>You will then see your files listed, ensure you are set to <a title=\"Click here to navigate to our guide and learn how to show hidden files in File Manager.\" href=\"\/support\/website\/show-hidden-files-in-file-manager\/\">show hidden files<\/a>.<\/li>\n<li>Navigate to the <a title=\"Click here to navigate to our guide and learn how to identify your website's document root directory.\" href=\"\/support\/website\/where-to-upload-files\/\">Document Root directory<\/a> for your website, locate the <em>.htaccess file<\/em>, and <b>right-click<\/b> it. This brings up a menu. Find and click on the <b>Edit<\/b> option.<br>\n<img decoding=\"async\" src=\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2012\/08\/cpanel_file-manager_edit-htaccess.png\" alt=\"Editing the htaccess file with cPanel File Manager\">\n<div style=\"clear: both;\"><\/div>\n<\/li>\n<li>You are now in the File Manager file editor. Paste your code into your <em>.htaccess file<\/em> so that it forces the visitor to download that type of file. The code should be formatted similar to that below but be much longer. (Some countries like China and the US can have thousands of lines in their block code.)\n<pre>order deny,allow\ndeny from 81.52.168.0\/23\ndeny from 188.138.10.163\/32\ndeny from 188.138.78.129\/32\nallow from all<\/pre>\n<\/li>\n<li>Be sure to hit the <b>Save Changes<\/b> button in the upper right corner to save your new .htaccess configuration. Now any IP from those ranges will be denied access to your site.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>cPanel has an IP blocking mechanism to help you secure your site from individuals who you deem suspicious or malicious. This works fine for a single IP or even a handful. It is not advisable however, if you want to block an entire country using your .htaccess file. People may want to block a country<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/\"> Read More ><\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4288],"tags":[],"class_list":["post-438","post","type-post","status-publish","format-standard","hentry","category-website"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Block Country IPs From Your Site Using htaccess | InMotion Hosting<\/title>\n<meta name=\"description\" content=\"Learn how to block a specific country from accessing your site by adding IP address to your .htaccess file.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Block Country IPs From Your Site Using htaccess | InMotion Hosting\" \/>\n<meta property=\"og:description\" content=\"Learn how to block a specific country from accessing your site by adding IP address to your .htaccess file.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2012-08-02T17:46:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-03T15:04:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2012\/03\/cpanel_file-manager-paper-lantern.png\" \/>\n<meta name=\"author\" content=\"Scott Mitchell\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Scott Mitchell\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/\"},\"author\":{\"name\":\"Scott Mitchell\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/d850efb28ef3573db7d24b0d8fa9eaed\"},\"headline\":\"Block Country IPs From Your Site Using htaccess\",\"datePublished\":\"2012-08-02T17:46:38+00:00\",\"dateModified\":\"2023-07-03T15:04:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/\"},\"wordCount\":413,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2012\/03\/cpanel_file-manager-paper-lantern.png\",\"articleSection\":[\"Website\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/\",\"name\":\"Block Country IPs From Your Site Using htaccess | InMotion Hosting\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2012\/03\/cpanel_file-manager-paper-lantern.png\",\"datePublished\":\"2012-08-02T17:46:38+00:00\",\"dateModified\":\"2023-07-03T15:04:11+00:00\",\"description\":\"Learn how to block a specific country from accessing your site by adding IP address to your .htaccess file.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#primaryimage\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2012\/03\/cpanel_file-manager-paper-lantern.png\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2012\/03\/cpanel_file-manager-paper-lantern.png\",\"width\":964,\"height\":196},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Block Country IPs From Your Site Using htaccess\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/d850efb28ef3573db7d24b0d8fa9eaed\",\"name\":\"Scott Mitchell\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/scott\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Block Country IPs From Your Site Using htaccess | InMotion Hosting","description":"Learn how to block a specific country from accessing your site by adding IP address to your .htaccess file.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/","og_locale":"en_US","og_type":"article","og_title":"Block Country IPs From Your Site Using htaccess | InMotion Hosting","og_description":"Learn how to block a specific country from accessing your site by adding IP address to your .htaccess file.","og_url":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2012-08-02T17:46:38+00:00","article_modified_time":"2023-07-03T15:04:11+00:00","og_image":[{"url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2012\/03\/cpanel_file-manager-paper-lantern.png","type":"","width":"","height":""}],"author":"Scott Mitchell","twitter_card":"summary_large_image","twitter_creator":"@InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"Scott Mitchell","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/"},"author":{"name":"Scott Mitchell","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/d850efb28ef3573db7d24b0d8fa9eaed"},"headline":"Block Country IPs From Your Site Using htaccess","datePublished":"2012-08-02T17:46:38+00:00","dateModified":"2023-07-03T15:04:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/"},"wordCount":413,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#primaryimage"},"thumbnailUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2012\/03\/cpanel_file-manager-paper-lantern.png","articleSection":["Website"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/","url":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/","name":"Block Country IPs From Your Site Using htaccess | InMotion Hosting","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#primaryimage"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#primaryimage"},"thumbnailUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2012\/03\/cpanel_file-manager-paper-lantern.png","datePublished":"2012-08-02T17:46:38+00:00","dateModified":"2023-07-03T15:04:11+00:00","description":"Learn how to block a specific country from accessing your site by adding IP address to your .htaccess file.","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#primaryimage","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2012\/03\/cpanel_file-manager-paper-lantern.png","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2012\/03\/cpanel_file-manager-paper-lantern.png","width":964,"height":196},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/website\/block-country-ips\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"Block Country IPs From Your Site Using htaccess"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/d850efb28ef3573db7d24b0d8fa9eaed","name":"Scott Mitchell","url":"https:\/\/www.inmotionhosting.com\/support\/author\/scott\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"primary_category":null,"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=438"}],"version-history":[{"count":5,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/438\/revisions"}],"predecessor-version":[{"id":105360,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/438\/revisions\/105360"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}