{"id":559,"date":"2013-02-07T18:48:49","date_gmt":"2013-02-07T18:48:49","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/2013\/02\/07\/access-protected-dir\/"},"modified":"2021-08-16T23:21:42","modified_gmt":"2021-08-17T03:21:42","slug":"access-protected-dir","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/","title":{"rendered":"Allow public access to a file in a protected directory using .htaccess"},"content":{"rendered":"\n<div>Within your website structure, there are many times when you may want to protect directories from outside access. This prevents any user from accessing a subdirectory of your site, and its files, without a username and password. There may be a time, however, when you want to allow access to a single file within a password directory and it is not feasible to move the file to an unprotected directory or folder. The instructions below will guide you in how to <strong>allow access to a single file in a password protected directory using your <code>.htaccess<\/code> file<\/strong>.<\/div>\n<div>&nbsp;<\/div>\n<h2>How to allow access to a file in a protected directory<\/h2>\n<div>&nbsp;<\/div>\n<div>\n<ol class=\"article_list\">\n<li><a href=\"\/support\/edu\/cpanel\/how-to-log-into-cpanel\/\" target=\"_blank\" rel=\"noopener noreferrer\">Log into your cPanel<\/a> dashboard.<\/li>\n<li><a href=\"\/support\/edu\/cpanel\/using-file-manager-in-cpanel\/\" target=\"_blank\" rel=\"noopener noreferrer\">Access the <em>File Manager<\/em><\/a> under the <em>Files<\/em> section and navigate to the password protected folder. Make sure you enable the ability to <a href=\"\/support\/website\/show-hidden-files-in-file-manager\/\" target=\"_blank\" rel=\"noopener noreferrer\">show hidden files<\/a> by clicking <em>Settings<\/em> at the top right and clicking the check box for <em>Show Hidden Files (dotfiles)<\/em>.<\/li>\n<li>Within the password protected folder will be an .<em>htaccess<\/em> file that contains the security code to activate the password popup. Highlight the <code>.htaccess<\/code> file and click on the <em>Edit<\/em> icon from the toolbar across the top of the page.<\/li>\n<li>Once inside the editor, you will see the security code. It will appear similar to the example below. Our example directory was test, so attempting to access<em> inmotiontesting.com\/test<\/em> resulted in a popup box asking for username and password.\n<br><code>AuthName \"test-protect\"<br>AuthUserFile \"\/home\/userna5\/.htpasswds\/public_html\/test\/passwd\"<br>AuthType Basic<br>require valid-user<\/code>\n<br>You will need to add the following code for each file you want to allow access to after the code above. In this example, we are allowing access to a file named <em>test.php<\/em>. Note the before the . in the filename and the $ at the end. You will want to do this for your file name as well to ensure access is given to that exact file.<br>\n<code>&lt;filesmatch \"test.php$\"=\"\"&gt;<br>Satisfy Any<br>Allow from all<\/code><\/li>\n<li>Click on the <em>Save Changes<\/em> button in the upper right corner to finalize and activate the code. Now you will be able to access the specific file named test.php but no other files within that directory.<\/li>\n<\/ol>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Within your website structure, there are many times when you may want to protect directories from outside access. This prevents any user from accessing a subdirectory of your site, and its files, without a username and password. There may be a time, however, when you want to allow access to a single file within a<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/\"> Read More ><\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4288],"tags":[],"class_list":["post-559","post","type-post","status-publish","format-standard","hentry","category-website"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Allow public access to a file in a protected directory using .htaccess | InMotion Hosting<\/title>\n<meta name=\"description\" content=\"Learn to password protect a directory but give access to a specific file in your .htaccess file.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Allow public access to a file in a protected directory using .htaccess | InMotion Hosting\" \/>\n<meta property=\"og:description\" content=\"Learn to password protect a directory but give access to a specific file in your .htaccess file.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2013-02-07T18:48:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-17T03:21:42+00:00\" \/>\n<meta name=\"author\" content=\"Scott Mitchell\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Scott Mitchell\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/\"},\"author\":{\"name\":\"Scott Mitchell\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/d850efb28ef3573db7d24b0d8fa9eaed\"},\"headline\":\"Allow public access to a file in a protected directory using .htaccess\",\"datePublished\":\"2013-02-07T18:48:49+00:00\",\"dateModified\":\"2021-08-17T03:21:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/\"},\"wordCount\":349,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"articleSection\":[\"Website\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/\",\"name\":\"Allow public access to a file in a protected directory using .htaccess | InMotion Hosting\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"datePublished\":\"2013-02-07T18:48:49+00:00\",\"dateModified\":\"2021-08-17T03:21:42+00:00\",\"description\":\"Learn to password protect a directory but give access to a specific file in your .htaccess file.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Allow public access to a file in a protected directory using .htaccess\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/d850efb28ef3573db7d24b0d8fa9eaed\",\"name\":\"Scott Mitchell\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/scott\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Allow public access to a file in a protected directory using .htaccess | InMotion Hosting","description":"Learn to password protect a directory but give access to a specific file in your .htaccess file.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/","og_locale":"en_US","og_type":"article","og_title":"Allow public access to a file in a protected directory using .htaccess | InMotion Hosting","og_description":"Learn to password protect a directory but give access to a specific file in your .htaccess file.","og_url":"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2013-02-07T18:48:49+00:00","article_modified_time":"2021-08-17T03:21:42+00:00","author":"Scott Mitchell","twitter_card":"summary_large_image","twitter_creator":"@InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"Scott Mitchell","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/"},"author":{"name":"Scott Mitchell","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/d850efb28ef3573db7d24b0d8fa9eaed"},"headline":"Allow public access to a file in a protected directory using .htaccess","datePublished":"2013-02-07T18:48:49+00:00","dateModified":"2021-08-17T03:21:42+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/"},"wordCount":349,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"articleSection":["Website"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/","url":"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/","name":"Allow public access to a file in a protected directory using .htaccess | InMotion Hosting","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"datePublished":"2013-02-07T18:48:49+00:00","dateModified":"2021-08-17T03:21:42+00:00","description":"Learn to password protect a directory but give access to a specific file in your .htaccess file.","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/website\/access-protected-dir\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"Allow public access to a file in a protected directory using .htaccess"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/d850efb28ef3573db7d24b0d8fa9eaed","name":"Scott Mitchell","url":"https:\/\/www.inmotionhosting.com\/support\/author\/scott\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"primary_category":null,"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/559","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=559"}],"version-history":[{"count":3,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/559\/revisions"}],"predecessor-version":[{"id":84974,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/559\/revisions\/84974"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}