{"id":564,"date":"2016-06-01T00:00:00","date_gmt":"2016-06-01T00:00:00","guid":{"rendered":"http:\/\/blog.hostinger.io\/hostinger-tutorials\/uncategorized\/htaccesshow-to-restrict-access-to-your-website-for-everyone-except-you\/"},"modified":"2026-11-06T08:33:53","modified_gmt":"2026-11-06T08:33:53","slug":"how-to-restrict-access-to-your-website-using-htaccess","status":"publish","type":"post","link":"\/uk\/tutorials\/how-to-restrict-access-to-your-website-using-htaccess\/","title":{"rendered":"How to restrict website access using .htaccess"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p class=\"wp-block-paragraph\">You can restrict access to your website using <code>.htaccess<\/code> rules that block specific IP addresses or permit only trusted visitors. This is useful when testing a website, limiting access to a development environment, or blocking unwanted traffic.<\/p><p class=\"wp-block-paragraph\">In this tutorial, you&#8217;ll learn how to edit the <code>.htaccess<\/code> file, configure IP-based restrictions, and verify that your access rules work without locking you out of your website.<\/p>\n\n\n\n<\/p><h2 id=\"h-what-is-htaccess\" class=\"wp-block-heading h-t-title-2\">Before restricting access with .htaccess<\/h2><p class=\"wp-block-paragraph\">The <code>.htaccess<\/code> file controls certain web server settings, including redirects and access restrictions. These instructions use Apache 2.4 access-control syntax, so make sure your hosting environment supports the relevant directives.<\/p><p class=\"wp-block-paragraph\">Before editing the file, create a backup of your existing <code>.htaccess<\/code> configuration. Incorrect rules can block legitimate visitors or cause server errors.<\/p><p class=\"wp-block-paragraph\">You&#8217;ll also need the public IP address you want to permit or block. If your IP address changes frequently, consider using password protection instead of relying on an IP-based restriction.<\/p><h2 id=\"h-how-to-edit-the-htaccess-file\" class=\"wp-block-heading h-t-title-2\">How to edit the .htaccess file<\/h2><p class=\"wp-block-paragraph\">If you want to edit the <strong>.htaccess<\/strong> file, you should enter the root folder of your site through your hosting control panel&#8217;s file manager or an <a data-click-id=\"hgr-post-content-link-ftp-client\" href=\"\/gb\/tutorials\/how-to-create-ftp-accounts\">FTP client<\/a> such as <a data-click-id=\"hgr-post-content-link-filezilla\" href=\"https:\/\/filezilla-project.org\" target=\"_blank\" rel=\"noopener\">FileZilla<\/a>.<\/p><p class=\"wp-block-paragraph\">To edit <code>.htaccess<\/code> using Hostinger File Manager:<\/p><ol start=\"1\" class=\"wp-block-list\">\n<li>Log in to your Hostinger account and open <strong>Websites<\/strong>.<\/li>\n\n\n\n<li>Find your website and click <strong>Manage site<\/strong>.<\/li>\n\n\n\n<li>Navigate to <strong>Files &rarr; File Manager<\/strong>.<\/li>\n\n\n\n<li>Open the <code>public_html<\/code> directory and locate <code>.htaccess<\/code>.<\/li>\n\n\n\n<li>Create a backup copy, then open the original file in the editor.<\/li>\n<\/ol><p class=\"wp-block-paragraph\">If <code>.htaccess<\/code> doesn&#8217;t exist, create a new file with that name. Don&#8217;t overwrite an existing file, as it may contain important WordPress or website configuration rules.<\/p><p class=\"wp-block-paragraph\">Save your changes. If you&#8217;re using the newer Hostinger File Manager, click <strong>Deploy<\/strong> to apply them to the live website.<\/p><p class=\"wp-block-paragraph\">You can start modifying the file right away. If you can&#8217;t <a data-click-id=\"hgr-post-content-link-find-the-htaccess-file\" href=\"\/gb\/tutorials\/locate-and-create-htaccess\/\">find the <strong>.htaccess<\/strong> file<\/a> in the <strong>public_html<\/strong> directory, you can create it yourself. Just click the <strong>New File<\/strong> button at the top right corner of the file manager, name it <strong>.htaccess<\/strong>, then click<strong> Create<\/strong>.<\/p><h2 id=\"h-how-to-restrict-website-access-by-ip-using-htaccess\" class=\"wp-block-heading h-t-title-2\">How to restrict website access by IP using .htaccess<\/h2><p class=\"wp-block-paragraph\">You can configure <code>.htaccess<\/code> to permit only specific visitors, block individual IP addresses, or deny access to everyone.<\/p><p class=\"wp-block-paragraph\">The following examples use Apache 2.4 <code>Require<\/code> directives instead of the older <code>Order<\/code>, <code>Allow<\/code>, and <code>Deny<\/code> syntax.<\/p><h3 class=\"wp-block-heading h-t-title-3\">Allow access only from your IP address<\/h3><p class=\"wp-block-paragraph\">To block everyone except one IP address, add:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Require ip 203.0.113.10<\/pre><p class=\"wp-block-paragraph\">Replace <code>203.0.113.10<\/code> with your public IP address. Only requests from the specified IP address will be permitted.<\/p><h3 class=\"wp-block-heading h-t-title-3\">Block a specific IP address<\/h3><p class=\"wp-block-paragraph\">To block one IP address while permitting other visitors, use:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;RequireAll&gt;\n    Require all granted\n    Require not ip 203.0.113.10\n&lt;\/RequireAll&gt;<\/pre><p class=\"wp-block-paragraph\">Replace the example address with the IP you want to block.<\/p><h3 class=\"wp-block-heading h-t-title-3\">Block access for everyone<\/h3><p class=\"wp-block-paragraph\">To deny all website requests, use:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Require all denied<\/pre><p class=\"wp-block-paragraph\">This blocks your access through the browser as well. Make sure you can still edit or restore <code>.htaccess<\/code> using your hosting control panel before applying this restriction.<\/p><p class=\"wp-block-paragraph\">Add only the rules needed for your access-control goal. Don&#8217;t combine these examples without checking how the authorization directives interact.<\/p><h2 id=\"h-how-to-test-your-htaccess-access-restrictions\" class=\"wp-block-heading h-t-title-2\">How to test your .htaccess access restrictions<\/h2><p class=\"wp-block-paragraph\">After saving your changes, open your website from an IP address that should have access and one that should be blocked.<\/p><p class=\"wp-block-paragraph\">Blocked visitors should receive a <code>403 Forbidden<\/code> response. If you&#8217;re testing an IP whitelist, confirm that your permitted IP can still access the website.<\/p><p class=\"wp-block-paragraph\">If you receive a <code>500 Internal Server Error<\/code>, your web server may not support the directive or the configuration may contain a syntax error.<\/p><p class=\"wp-block-paragraph\">Restore your backed-up <code>.htaccess<\/code> file if the restriction behaves unexpectedly. If you use a CDN or reverse proxy, verify that the server identifies visitors&#8217; real IP addresses before relying on IP-based rules.<\/p><h2 id=\"h-conclusion\" class=\"wp-block-heading h-t-title-2\">Next steps: Keep your website access secure<\/h2><p class=\"wp-block-paragraph\">Once you&#8217;ve confirmed that your access restrictions work, review them whenever your trusted IP addresses change.<\/p><p class=\"wp-block-paragraph\">Remove temporary restrictions when your website is ready for visitors. If you need ongoing protection for private content, consider password-based access rather than depending entirely on IP addresses.<\/p><p class=\"wp-block-paragraph\">Keep a backup of your working <code>.htaccess<\/code> configuration so you can restore access if a future change causes problems.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can restrict access to your website using .htaccess rules that block specific IP addresses or permit only trusted visitors. This is useful when testing a website, limiting access to a development environment, or blocking unwanted traffic. In this tutorial, you&#8217;ll learn how to edit the .htaccess file, configure IP-based restrictions, and verify that your [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/uk\/tutorials\/how-to-restrict-access-to-your-website-using-htaccess\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":158,"featured_media":140417,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to restrict website access using .htaccess","rank_math_description":"Learn how to restrict website access using .htaccess. Block specific IP addresses, allow trusted visitors, and test your access rules safely.","rank_math_focus_keyword":"htaccess deny from all","_content_updated_date":"2019-09-16","footnotes":""},"categories":[22709],"tags":[],"class_list":["post-564","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technical-aspects"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-restrict-access-to-your-website-using-htaccess\/","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-restrict-access-to-your-website-using-htaccess\/","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-restrict-access-to-your-website-using-htaccess\/","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-restrict-access-to-your-website-using-htaccess\/","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-restrict-access-to-your-website-using-htaccess\/","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-restrict-access-to-your-website-using-htaccess\/","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-restrict-access-to-your-website-using-htaccess\/","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-restrict-access-to-your-website-using-htaccess\/","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/users\/158"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/comments?post=564"}],"version-history":[{"count":16,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/564\/revisions"}],"predecessor-version":[{"id":140415,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/564\/revisions\/140415"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/media\/140417"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/media?parent=564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/categories?post=564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/tags?post=564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}