{"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-03-09T19:20:15","modified_gmt":"2026-03-09T19:20:15","slug":"how-to-restrict-access-to-your-website-using-htaccess","status":"publish","type":"post","link":"\/ng\/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":"<?xml encoding=\"utf-8\" ?><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\"><img loading=\"lazy\" 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=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure><p>\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=\"\/ng\/tutorials\/htaccess\/how-to-change-timezone-using-htaccess\">changing your site&rsquo;s time zone<\/a>, making a custom error page, <a href=\"\/ng\/tutorials\/change-index-page-in-htaccess-with-directoryindex\">changing the default index page<\/a> or <a href=\"\/ng\/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=\"\/ng\/tutorials\/how-to-create-ftp-accounts\">FTP client<\/a> such as <a href=\"https:\/\/filezilla-project.org\">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 loading=\"lazy\" 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=\"auto, (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\">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?\">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=\"\/ng\/tutorials\/htaccess\/how-to-allow-or-block-visitors-from-specific-countries-using-htaccess\">here<\/a>.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-full\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-web-hosting\" href=\"\/ng\/web-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" 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=\"auto, (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 it. You can do so by adding the deny from all command to .htaccess. 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 .htaccess [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ng\/tutorials\/how-to-restrict-access-to-your-website-using-htaccess\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":158,"featured_media":145452,"comment_status":"open","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":[22630],"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-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\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/users\/158"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/comments?post=564"}],"version-history":[{"count":16,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/564\/revisions"}],"predecessor-version":[{"id":145451,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/564\/revisions\/145451"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media\/145452"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media?parent=564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/categories?post=564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/tags?post=564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}