{"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":"2025-12-22T13:24:58","modified_gmt":"2025-12-22T13:24:58","slug":"how-to-restrict-access-to-your-website-using-htaccess","status":"publish","type":"post","link":"\/tutorials\/how-to-restrict-access-to-your-website-using-htaccess","title":{"rendered":".htaccess &#8220;deny from all&#8221; command: how to restrict site access"},"content":{"rendered":"<p>If you&rsquo;re currently testing your site or setting it to maintenance mode, you might want to restrict visitors from accessing it. You can do so by adding the<strong> deny from all<\/strong> command to <strong>.htaccess<\/strong>.<\/p><p>In this tutorial, we&rsquo;ll show you exactly how to do it. But first, let&rsquo;s take an in-depth look at the <strong>.htaccess <\/strong>file.<\/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=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/public\" alt=\"\" class=\"wp-image-69260\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=2048,fit=scale-down 2048w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure><p>\n\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-what-is-htaccess\">What is .htaccess?<\/h2><p><strong>.htaccess<\/strong> stands for <strong>Hypertext Access<\/strong> &ndash; it&rsquo;s a configuration file which is used by Apache-based web servers to modify the server&rsquo;s behavior.<\/p><p>You can also use the file for other purposes, such as creating a password for your site, <a href=\"\/tutorials\/htaccess\/how-to-change-timezone-using-htaccess\">changing your site&rsquo;s time zone<\/a>, making a custom error page, <a href=\"\/tutorials\/change-index-page-in-htaccess-with-directoryindex\">changing the default index page<\/a> or <a href=\"\/tutorials\/how-to-redirect-non-www-urls-to-www\">redirecting URLs<\/a>. You just need to add a few commands to <strong>.htaccess<\/strong> to make it happen.<\/p><p>For example, <strong>deny from all<\/strong> is a command that will allow you to apply access restrictions to your site.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-edit-the-htaccess-file\">How to edit the .htaccess file?<\/h2><p>If you want to edit the <strong>.htaccess<\/strong> file, you should enter the root folder of your site through your hosting control panel&rsquo;s file manager or an <a href=\"\/tutorials\/how-to-create-ftp-accounts\">FTP client<\/a> such as <a href=\"https:\/\/filezilla-project.org\" target=\"_blank\" rel=\"noopener\">FileZilla<\/a>.<\/p><p>Let&rsquo;s cover how to edit an existing<strong> .htaccess<\/strong> file using Hostinger&rsquo;s hPanel:<\/p><ol class=\"wp-block-list\">\n<li>Log in to the<strong> hPanel<\/strong>.<\/li>\n\n\n\n<li>Enter the <strong>File Manager<\/strong>, which is located under the <strong>Files<\/strong> section.<\/li>\n\n\n\n<li>Access the <strong>public_html<\/strong> directory.<\/li>\n\n\n\n<li>Look for the <strong>.htaccess<\/strong> file, right-click on it, and choose <strong>edit<\/strong>.<img decoding=\"async\" class=\"aligncenter wp-image-19037 size-full\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2016\/06\/htaccess-file-in-hpanel-before-adding-disallow-all-command.png\" alt=\"editing htaccess file via hPanel\" width=\"751\" height=\"263\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2016\/06\/htaccess-file-in-hpanel-before-adding-disallow-all-command.png\/w=751,fit=scale-down 751w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2016\/06\/htaccess-file-in-hpanel-before-adding-disallow-all-command.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2016\/06\/htaccess-file-in-hpanel-before-adding-disallow-all-command.png\/w=300,fit=scale-down 300w\" sizes=\"(max-width: 751px) 100vw, 751px\" \/><\/li>\n<\/ol><p>You can start modifying the file right away. If you can&rsquo;t find the <strong>.htaccess<\/strong> file 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 class=\"wp-block-heading\" id=\"h-how-to-use-htaccess-deny-from-all-to-restrict-access\">How to use .htaccess &ldquo;deny from all&rdquo; to restrict access<\/h2><p>Since a complete restriction would apply to your IP address too, you should identify your IP address beforehand using a tool like <a href=\"https:\/\/whatismyipaddress.com\" target=\"_blank\" rel=\"noopener\">What Is My IP Address<\/a> and create an exception.<\/p><p>Make sure that your IP address is <a href=\"https:\/\/support.google.com\/fiber\/answer\/3547208?\" target=\"_blank\" rel=\"noopener\">static<\/a>, not dynamic, so you won&rsquo;t have to change it in the <strong>.htaccess<\/strong> file frequently.<\/p><p>Now, let&rsquo;s place the <strong>deny from all<\/strong> command in the<strong> .htaccess<\/strong> file. Add the following code snippet to the top of the file if you want to block all access except yours:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">order allow,deny\n\ndeny from all\n\nallow from IP<\/pre><p>Replace<strong> IP<\/strong> with your IP address to create the exception.<\/p><p>Now, if you want to allow access from all IP addresses but restrict access from a specific one, you can use this format:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">order allow,deny\n\ndeny from UndesiredIP\n\nallow from all<\/pre><p>Here, as in the previous example, replace <strong>UndesiredIP<\/strong> with the IP address you want to restrict. Make sure to save the <strong>.htaccess<\/strong> file to apply the changes.<\/p><p>If you want to block access from specific&nbsp;<strong>countries<\/strong>, check out our other article <a href=\"\/tutorials\/htaccess\/how-to-allow-or-block-visitors-from-specific-countries-using-htaccess\">here<\/a>.<\/p><figure class=\"wp-block-image size-full\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-web-hosting\" href=\"\/web-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/public\" alt=\"Hostinger web hosting banner\" class=\"wp-image-98604\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Now you&rsquo;ve learned that restricting access to your site can be done by using <strong>.htaccess<\/strong> with the <strong>deny from all<\/strong> command. Don&rsquo;t forget to allow access to your own IP address!<\/p><p>Do you have further questions regarding the<strong> .htaccess deny from all<\/strong> command? Let us know in the comment section.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&rsquo;re currently testing your site or setting it to maintenance mode, you might want to restrict visitors from accessing [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/tutorials\/how-to-restrict-access-to-your-website-using-htaccess\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":158,"featured_media":843,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Restrict Access to Your Site Using .htaccess deny from all","rank_math_description":"You can restrict visitors from viewing your site by adding the deny from all command to the .htaccess file. Here, we'll show you how to do it!","rank_math_focus_keyword":"htaccess deny from all","footnotes":""},"categories":[22628,22630],"tags":[],"class_list":["post-564","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hosting","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-UK","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-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-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\/tutorials\/wp-json\/wp\/v2\/posts\/564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/users\/158"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/comments?post=564"}],"version-history":[{"count":15,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/564\/revisions"}],"predecessor-version":[{"id":138130,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/564\/revisions\/138130"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media\/843"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media?parent=564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/categories?post=564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/tags?post=564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}