{"id":50426,"date":"2026-11-20T05:24:09","date_gmt":"2026-11-20T05:24:09","guid":{"rendered":"https:\/\/kickhost.com\/guides\/how-to-restrict-access-to-directories-by-ip-address\/"},"modified":"2026-11-28T09:21:10","modified_gmt":"2026-11-28T09:21:10","slug":"how-to-restrict-access-to-directories-by-ip-address","status":"publish","type":"kickhost_tutorial","link":"https:\/\/kickhost.com\/en-ke\/guides\/how-to-restrict-access-to-directories-by-ip-address\/","title":{"rendered":"How to Restrict Access to Directories by IP Address"},"content":{"rendered":"<p>Limiting your admin area to selected IP addresses is a simple way to keep attackers out. Only visitors from the allowed addresses can open the folder.<\/p>\n<p>To secure your admin area from hackers, you should only allow access to your admin directory from selected IP addresses. You can create a dot htaccess file in the directory where you want to restrict access to specific IP addresses.<\/p>\n<p>For example, if you have a WordPress blog installed on your main directory and you log in via example.com\/wp-admin, you should create an htaccess file in <strong>\/wp-admin\/.htaccess<\/strong> and put the following code into it. Please, don&#8217;t forget to replace the allowed IP address with your IP address.<\/p>\n<pre class=\"language-markup\"><code>order deny, allow\ndeny from all\nallow from YOUR-IP-ADDRESS-HERE<\/code><\/pre>\n<p>Replace the <strong>Your-IP-Address-Here<\/strong> text with your IP address.<\/p>\n<p>You can test this by accessing the wp-admin directory from another IP address, not mentioned in your htaccess file.<\/p>\n<h2>Know your IP address first<\/h2>\n<p>Check your own address before you add the rule. If your address changes, you may lock yourself out, so use this only if you have a stable connection.<\/p>\n<h2>Test and keep a backup<\/h2>\n<p>Download a copy of the .htaccess file before editing. After saving, test from an allowed and a blocked connection. If you see a 500 error, restore the copy.<\/p>\n<h2>Frequently asked questions<\/h2>\n<p><strong>What if my IP changes?<\/strong> Edit the rule and add the new address, or remove the restriction in File Manager.<\/p>\n<p><strong>Is this enough to secure WordPress?<\/strong> It helps, but also use strong passwords, updates and two-factor login.<\/p>\n<h2>Related guides<\/h2>\n<ul>\n<li><a href=\"https:\/\/kickhost.com\/en-ke\/guides\/how-to-edit-dothtaccess-file-in-the-cpanel-file-manager\/\">Edit the .htaccess file<\/a><\/li>\n<li><a href=\"https:\/\/kickhost.com\/en-ke\/guides\/how-to-password-protect-a-directory-in-cpanel\/\">Password protect a directory<\/a><\/li>\n<\/ul>\n<p>Need cPanel hosting in Kenya? <a href=\"https:\/\/kickhost.com\/en-ke\/web-hosting\/\">See KickHost hosting plans<\/a> or <a href=\"https:\/\/kickhost.com\/en-ke\/contact\/\">contact our team<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Restrict access to a directory by IP address with an .htaccess file. Steps for KickHost customers in Kenya.<\/p>\n","protected":false},"featured_media":0,"template":"","class_list":["post-50426","kickhost_tutorial","type-kickhost_tutorial","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/kickhost.com\/en-ke\/wp-json\/wp\/v2\/kickhost_tutorial\/50426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kickhost.com\/en-ke\/wp-json\/wp\/v2\/kickhost_tutorial"}],"about":[{"href":"https:\/\/kickhost.com\/en-ke\/wp-json\/wp\/v2\/types\/kickhost_tutorial"}],"version-history":[{"count":3,"href":"https:\/\/kickhost.com\/en-ke\/wp-json\/wp\/v2\/kickhost_tutorial\/50426\/revisions"}],"predecessor-version":[{"id":53420,"href":"https:\/\/kickhost.com\/en-ke\/wp-json\/wp\/v2\/kickhost_tutorial\/50426\/revisions\/53420"}],"wp:attachment":[{"href":"https:\/\/kickhost.com\/en-ke\/wp-json\/wp\/v2\/media?parent=50426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}