{"id":24222,"date":"2022-02-02T14:25:22","date_gmt":"2022-02-02T14:25:22","guid":{"rendered":"https:\/\/1-grid.com\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/"},"modified":"2023-10-19T13:01:57","modified_gmt":"2023-10-19T13:01:57","slug":"security-blocking-ip-addresses-and-countries-using-htaccess","status":"publish","type":"ht_kb","link":"https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/","title":{"rendered":"Security: Blocking IP Addresses and Countries using .htaccess"},"content":{"rendered":"<blockquote><p><span style=\"font-family: Helvetica,sans-serif;\">This article provides you with information on how to Block IP address and specific countries from your website by editing your .htaccess file.<\/span><\/p><\/blockquote>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><span style=\"font-size: 18px;\"><strong>What is .htaccess ?<\/strong><\/span><\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\">.htaccess is a configuration file for use on web servers running the Apache Web Server software. All our <a href=\"https:\/\/1-grid.com\/web-hosting\/\" rel=\"noreferrer noopener\" target=\"_blank\">Linux hosting control panels<\/a> have Apache running on the back end. These .htaccess files can be used to alter the configuration of you hosting space \u00a0to enable\/disable additional functionality and features. \u00a0These facilities include basic redirect functionality, for instance if a 404 file not found error occurs, or for more advanced functions.<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><span style=\"font-size: 18px;\"><strong>Configuring your .htaccess file<\/strong><\/span><\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\">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:<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><strong>*** All IP address below are examples, you will need to replace them with the IP addresses you intend to block from your site.<\/strong><\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><strong><span style=\"font-size: 14px;\">order allow,<br style='box-sizing: border-box; -webkit-font-smoothing: antialiased; text-rendering: optimizelegibility; color: rgb(34, 34, 34); font-family: \"Open Sans\", \"Lucida Sans Unicode\", \"Lucida Grande\", Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;  text-decoration-style: initial; text-decoration-color: initial;'>deny deny from 144.5.56.77<br style='box-sizing: border-box; -webkit-font-smoothing: antialiased; text-rendering: optimizelegibility; color: rgb(34, 34, 34); font-family: \"Open Sans\", \"Lucida Sans Unicode\", \"Lucida Grande\", Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;  text-decoration-style: initial; text-decoration-color: initial;'>deny from 12.34.23.107<br style='box-sizing: border-box; -webkit-font-smoothing: antialiased; text-rendering: optimizelegibility; color: rgb(34, 34, 34); font-family: \"Open Sans\", \"Lucida Sans Unicode\", \"Lucida Grande\", Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;  text-decoration-style: initial; text-decoration-color: initial;'>allow from all<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\">What if the unwanted visitor is from a different country and keeps changing their IP? Provided your website isn\u2019t 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.<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica, sans-serif; font-size: 14px;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica, sans-serif;\"><strong><span style=\"font-size: 14px;\">GeoIPEnable On<br style='box-sizing: border-box; -webkit-font-smoothing: antialiased; text-rendering: optimizelegibility; color: rgb(34, 34, 34); font-family: \"Open Sans\", \"Lucida Sans Unicode\", \"Lucida Grande\", Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;  text-decoration-style: initial; text-decoration-color: initial;'># Add countries you wish to deny here<br style='box-sizing: border-box; -webkit-font-smoothing: antialiased; text-rendering: optimizelegibility; color: rgb(34, 34, 34); font-family: \"Open Sans\", \"Lucida Sans Unicode\", \"Lucida Grande\", Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;  text-decoration-style: initial; text-decoration-color: initial;'>SetEnvIf GEOIP_COUNTRY_CODE CO DenyCountry<br style='box-sizing: border-box; -webkit-font-smoothing: antialiased; text-rendering: optimizelegibility; color: rgb(34, 34, 34); font-family: \"Open Sans\", \"Lucida Sans Unicode\", \"Lucida Grande\", Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;  text-decoration-style: initial; text-decoration-color: initial;'>SetEnvIf GEOIP_COUNTRY_CODE EG DenyCountry<br style='box-sizing: border-box; -webkit-font-smoothing: antialiased; text-rendering: optimizelegibility; color: rgb(34, 34, 34); font-family: \"Open Sans\", \"Lucida Sans Unicode\", \"Lucida Grande\", Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;  text-decoration-style: initial; text-decoration-color: initial;'>SetEnvIf GEOIP_COUNTRY_CODE HI DenyCountry<br style='box-sizing: border-box; -webkit-font-smoothing: antialiased; text-rendering: optimizelegibility; color: rgb(34, 34, 34); font-family: \"Open Sans\", \"Lucida Sans Unicode\", \"Lucida Grande\", Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;  text-decoration-style: initial; text-decoration-color: initial;'>Allow from all<br style='box-sizing: border-box; -webkit-font-smoothing: antialiased; text-rendering: optimizelegibility; color: rgb(34, 34, 34); font-family: \"Open Sans\", \"Lucida Sans Unicode\", \"Lucida Grande\", Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;  text-decoration-style: initial; text-decoration-color: initial;'>Deny from env=DenyCountry<\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><strong>INFO:\u00a0<\/strong>A list of all country codes can be found <a href=\"http:\/\/dev.maxmind.com\/geoip\/legacy\/codes\/iso3166\" rel=\"noreferrer noopener\" target=\"_blank\">here<\/a>.<\/span><\/p>\n<p><span style=\"font-family: Helvetica,sans-serif;\"><br \/>\n<\/span><\/p>\n<hr>\n<p><strong>TIP:\u00a0<\/strong>Should you require more information regarding \u00a0<a href=\"http:\/\/www.htaccess-guide.com\/\" rel=\"noreferrer noopener\" target=\"_blank\">.htaccess we would advise this article here.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article provides you with information on how to Block IP address and specific countries from your website by editing your .htaccess file. What is .htaccess ? .htaccess is a configuration file for use on web servers running the Apache Web Server software. All our Linux hosting control panels have&#8230;<\/p>\n","protected":false},"author":21,"comment_status":"open","ping_status":"open","template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"ht-kb-category":[],"ht-kb-tag":[1106],"class_list":["post-24222","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_tag-web-hosting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Blocking IP Addresses And Countries Using .htaccess<\/title>\n<meta name=\"description\" content=\"Concerned about security? Learn how to block IP addresses and countries using .htaccess with our guide from 1-grid&#039;s Knowledge Base\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Blocking IP Addresses And Countries Using .htaccess\" \/>\n<meta property=\"og:description\" content=\"Concerned about security? Learn how to block IP addresses and countries using .htaccess with our guide from 1-grid&#039;s Knowledge Base\" \/>\n<meta property=\"og:url\" content=\"https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/\" \/>\n<meta property=\"og:site_name\" content=\"1-grid Knowledge Base\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/1grid.co.za\/\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-19T13:01:57+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@1grid_hosting\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/\",\"url\":\"https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/\",\"name\":\"Blocking IP Addresses And Countries Using .htaccess\",\"isPartOf\":{\"@id\":\"https:\/\/1grid.co.za\/knowledge\/#website\"},\"datePublished\":\"2022-02-02T14:25:22+00:00\",\"dateModified\":\"2023-10-19T13:01:57+00:00\",\"description\":\"Concerned about security? Learn how to block IP addresses and countries using .htaccess with our guide from 1-grid's Knowledge Base\",\"breadcrumb\":{\"@id\":\"https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/1grid.co.za\/knowledge\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Security: Blocking IP Addresses and Countries using .htaccess\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/1grid.co.za\/knowledge\/#website\",\"url\":\"https:\/\/1grid.co.za\/knowledge\/\",\"name\":\"1-Grid Domain Hosting Knowledge Base\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/1grid.co.za\/knowledge\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/1grid.co.za\/knowledge\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/1grid.co.za\/knowledge\/#organization\",\"name\":\"1-Grid Domain Hosting Knowledge Base\",\"url\":\"https:\/\/1grid.co.za\/knowledge\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/1grid.co.za\/knowledge\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/1grid.co.za\/knowledge\/wp-content\/uploads\/2023\/01\/1-grid-logo-color.svg\",\"contentUrl\":\"https:\/\/1grid.co.za\/knowledge\/wp-content\/uploads\/2023\/01\/1-grid-logo-color.svg\",\"width\":100,\"height\":100,\"caption\":\"1-Grid Domain Hosting Knowledge Base\"},\"image\":{\"@id\":\"https:\/\/1grid.co.za\/knowledge\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/1grid.co.za\/\",\"https:\/\/twitter.com\/1grid_hosting\",\"https:\/\/www.instagram.com\/1grid_hosting\/\",\"https:\/\/za.linkedin.com\/company\/1-grid\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Blocking IP Addresses And Countries Using .htaccess","description":"Concerned about security? Learn how to block IP addresses and countries using .htaccess with our guide from 1-grid's Knowledge Base","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:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/","og_locale":"en_US","og_type":"article","og_title":"Blocking IP Addresses And Countries Using .htaccess","og_description":"Concerned about security? Learn how to block IP addresses and countries using .htaccess with our guide from 1-grid's Knowledge Base","og_url":"https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/","og_site_name":"1-grid Knowledge Base","article_publisher":"https:\/\/www.facebook.com\/1grid.co.za\/","article_modified_time":"2023-10-19T13:01:57+00:00","twitter_card":"summary_large_image","twitter_site":"@1grid_hosting","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/","url":"https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/","name":"Blocking IP Addresses And Countries Using .htaccess","isPartOf":{"@id":"https:\/\/1grid.co.za\/knowledge\/#website"},"datePublished":"2022-02-02T14:25:22+00:00","dateModified":"2023-10-19T13:01:57+00:00","description":"Concerned about security? Learn how to block IP addresses and countries using .htaccess with our guide from 1-grid's Knowledge Base","breadcrumb":{"@id":"https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/1grid.co.za\/knowledge\/security-blocking-ip-addresses-and-countries-using-htaccess\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/1grid.co.za\/knowledge\/"},{"@type":"ListItem","position":2,"name":"Security: Blocking IP Addresses and Countries using .htaccess"}]},{"@type":"WebSite","@id":"https:\/\/1grid.co.za\/knowledge\/#website","url":"https:\/\/1grid.co.za\/knowledge\/","name":"1-Grid Domain Hosting Knowledge Base","description":"","publisher":{"@id":"https:\/\/1grid.co.za\/knowledge\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/1grid.co.za\/knowledge\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/1grid.co.za\/knowledge\/#organization","name":"1-Grid Domain Hosting Knowledge Base","url":"https:\/\/1grid.co.za\/knowledge\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/1grid.co.za\/knowledge\/#\/schema\/logo\/image\/","url":"https:\/\/1grid.co.za\/knowledge\/wp-content\/uploads\/2023\/01\/1-grid-logo-color.svg","contentUrl":"https:\/\/1grid.co.za\/knowledge\/wp-content\/uploads\/2023\/01\/1-grid-logo-color.svg","width":100,"height":100,"caption":"1-Grid Domain Hosting Knowledge Base"},"image":{"@id":"https:\/\/1grid.co.za\/knowledge\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/1grid.co.za\/","https:\/\/twitter.com\/1grid_hosting","https:\/\/www.instagram.com\/1grid_hosting\/","https:\/\/za.linkedin.com\/company\/1-grid"]}]}},"_links":{"self":[{"href":"https:\/\/1grid.co.za\/knowledge\/wp-json\/wp\/v2\/ht-kb\/24222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1grid.co.za\/knowledge\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/1grid.co.za\/knowledge\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/1grid.co.za\/knowledge\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/1grid.co.za\/knowledge\/wp-json\/wp\/v2\/comments?post=24222"}],"version-history":[{"count":2,"href":"https:\/\/1grid.co.za\/knowledge\/wp-json\/wp\/v2\/ht-kb\/24222\/revisions"}],"predecessor-version":[{"id":33011,"href":"https:\/\/1grid.co.za\/knowledge\/wp-json\/wp\/v2\/ht-kb\/24222\/revisions\/33011"}],"wp:attachment":[{"href":"https:\/\/1grid.co.za\/knowledge\/wp-json\/wp\/v2\/media?parent=24222"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/1grid.co.za\/knowledge\/wp-json\/wp\/v2\/ht-kb-category?post=24222"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/1grid.co.za\/knowledge\/wp-json\/wp\/v2\/ht-kb-tag?post=24222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}