{"id":529,"date":"2019-11-15T02:54:13","date_gmt":"2019-11-15T02:54:13","guid":{"rendered":"http:\/\/blog.hostinger.io\/hostinger-tutorials\/%category\/htaccesshow-to-allow-or-block-visitors-from-specific-countries-using-htaccess\/"},"modified":"2025-04-13T08:11:47","modified_gmt":"2025-04-13T08:11:47","slug":"how-to-block-visitors-from-countries-using-htaccess","status":"publish","type":"post","link":"\/in\/tutorials\/how-to-block-visitors-from-countries-using-htaccess","title":{"rendered":"How to Block IP by Country: Restrict Access to Your Website from Specific Countries Using .htaccess"},"content":{"rendered":"<p>This quick and easy tutorial will show you how to control site access based on visitors&rsquo; location. With some tweaks to the <strong>.htacess<\/strong> file, it&rsquo;s possible to allow or block visitors from certain countries. Keep reading!<\/p><figure class=\"wp-block-image size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/How-to-Speed-Up-Your-Website-EN.pdf\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"1024\" height=\"283\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website-1024x283.png\" alt=\"\" class=\"wp-image-69260\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/eBook-Speed-Up-your-website-1536x425.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/eBook-Speed-Up-your-website-300x83.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/eBook-Speed-Up-your-website-150x41.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/eBook-Speed-Up-your-website-768x212.png 768w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2022\/11\/eBook-Speed-Up-your-website.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-allowing-or-blocking-visitors-from-specific-countries-using-htaccess\">Allowing or Blocking Visitors From Specific Countries Using .htaccess<\/h2><p>Once launched, a website is available worldwide. However, in many cases, it&rsquo;s necessary to control your site access, especially when you want to stop spammers and hackers from particular countries.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-full\"><a href=\"\/in\/web-hosting\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\" alt=\"Hostinger web hosting banner\" class=\"wp-image-98604\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/11\/Web-hosting_in-text-banner.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/11\/Web-hosting_in-text-banner-300x88.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/11\/Web-hosting_in-text-banner-150x44.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/11\/Web-hosting_in-text-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p>Fortunately, you can use your WordPress <strong>.htaccess<\/strong> file to allow or block visitors from specific countries. Let&rsquo;s learn how to do so.<\/p><h3 class=\"wp-block-heading\" id=\"h-step-1-generate-the-country-s-ip-addresses\">Step 1: Generate the Country&rsquo;s IP Addresses<\/h3><p>Plenty of online tools are available to allow or block visitors according to their country. In this tutorial, we&rsquo;ll be using <strong>IP2Location<\/strong>.<\/p><ol class=\"wp-block-list\">\n<li>Head to the <a href=\"https:\/\/www.ip2location.com\/free\/visitor-blocker\" target=\"_blank\" rel=\"noopener\">IP2Location Firewall IP list tool<\/a>.<\/li>\n\n\n\n<li>Select the country you want to block or allow.<\/li>\n\n\n\n<li>Choose between IPv4 and IPv6 in the <strong>IP Version<\/strong> menu.<\/li>\n\n\n\n<li>Choose the format in the <strong>Output Format<\/strong> menu. The choice depends on whether you want to block or allow visitors from those countries.<\/li>\n\n\n\n<li>Click <strong>Download<\/strong>.<\/li>\n<\/ol><figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/01\/image-1.png\"><img decoding=\"async\" width=\"971\" height=\"191\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/01\/image-1.png\" alt=\"The interface of IP2Location IP list tool, showing the country, IP version, and output format menus.\" class=\"wp-image-101527\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2024\/01\/image-1.png 971w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2024\/01\/image-1-300x59.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2024\/01\/image-1-150x30.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2024\/01\/image-1-768x151.png 768w\" sizes=\"(max-width: 971px) 100vw, 971px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"6\">\n<li>The tool will download the Access Control List (ACL) into your computer.<\/li>\n\n\n\n<li>If you are using the <strong>allow<\/strong> function, make sure to insert the line <strong>deny from all&nbsp;<\/strong>above the list of allowed IPs.<\/li>\n<\/ol><h3 class=\"wp-block-heading\" id=\"h-step-2-insert-the-generated-ip-addresses-into-the-htaccess-file\">Step 2: Insert the Generated IP Addresses into the .htaccess File<\/h3><p>Finally, paste the IP addresses of the countries you want to block or allow to <a href=\"\/in\/tutorials\/locate-and-create-htaccess\"><strong>.htaccess<\/strong> file<\/a>. Here&rsquo;s how to do it using Hostinger&rsquo;s hPanel:<\/p><ol class=\"wp-block-list\">\n<li>Go to <strong>Files<\/strong> &rarr; <strong>File Manager<\/strong>.<\/li>\n\n\n\n<li>Select your domain and hit <strong>Go To File Manager<\/strong>.<\/li>\n\n\n\n<li>Navigate to the <strong>public_html<\/strong> folder and double-click the <strong>.htaccess<\/strong> file.<\/li>\n\n\n\n<li>Open the ACL file on your computer, paste it to your .htaccess file, and hit <strong>Save<\/strong>. Your <strong>.htaccess<\/strong> file will look like this:<\/li>\n<\/ol><figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/01\/image-2.png\"><img decoding=\"async\" width=\"904\" height=\"550\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/01\/image-2.png\" alt=\"An .htaccess file containing an ACL\" class=\"wp-image-101528\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2024\/01\/image-2.png 904w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2024\/01\/image-2-300x183.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2024\/01\/image-2-150x91.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2024\/01\/image-2-768x467.png 768w\" sizes=\"(max-width: 904px) 100vw, 904px\" \/><\/a><\/figure><p>You can also use an FTP client to edit the <strong>.htaccess<\/strong> file.<\/p><p>\n\n\n<div><p class=\"important\"><strong>Important!<\/strong> If you cannot access your website after inserting the generated IP addresses, check whether your IP address is included on the block list. You can find your IP address via <a href=\"https:\/\/whatismyipaddress.com\/\" target=\"_blank\" rel=\"noopener\">What Is My IP Address<\/a><\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>In this tutorial, you&rsquo;ve learned the easy way to block or allow visitors from specific countries. All you need to do is generate the country&rsquo;s IP address via <strong>IP2Location<\/strong>, then insert an ACL into your <strong>.htaccess<\/strong> file.<\/p><p>We hope that this guide was helpful. Let us know in the comments if you have any questions.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-full\"><a href=\"\/in\/web-hosting\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\" alt=\"Hostinger web hosting banner\" class=\"wp-image-98604\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/11\/Web-hosting_in-text-banner.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/11\/Web-hosting_in-text-banner-300x88.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/11\/Web-hosting_in-text-banner-150x44.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/11\/Web-hosting_in-text-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>This quick and easy tutorial will show you how to control site access based on visitors&rsquo; location. With some tweaks to the .htacess file, it&rsquo;s possible to allow or block visitors from certain countries. Keep reading! Allowing or Blocking Visitors From Specific Countries Using .htaccess Once launched, a website is available worldwide. However, in many [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/in\/tutorials\/how-to-block-visitors-from-countries-using-htaccess\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"","rank_math_description":"","rank_math_focus_keyword":"","footnotes":""},"categories":[22624,22626],"tags":[],"class_list":["post-529","post","type-post","status-publish","format-standard","hentry","category-hosting","category-technical-aspects"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-block-visitors-from-countries-using-htaccess","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/como-bloquear-acessos-de-ip-via-htaccess","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/comment-bloquer-une-adresse-ip","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/como-bloquear-una-direccion-ip","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-block-ip","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-block-visitors-from-countries-using-htaccess","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/como-bloquear-una-direccion-ip","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/como-bloquear-una-direccion-ip","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/como-bloquear-una-direccion-ip","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/como-bloquear-acessos-de-ip-via-htaccess","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-block-visitors-from-countries-using-htaccess","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-block-visitors-from-countries-using-htaccess","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-block-visitors-from-countries-using-htaccess","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-block-visitors-from-countries-using-htaccess","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-block-visitors-from-countries-using-htaccess","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-block-visitors-from-countries-using-htaccess","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/comments?post=529"}],"version-history":[{"count":23,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/529\/revisions"}],"predecessor-version":[{"id":111311,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/529\/revisions\/111311"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/media?parent=529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/categories?post=529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/tags?post=529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}