{"id":1875,"date":"2010-11-15T10:25:00","date_gmt":"2010-11-15T10:25:00","guid":{"rendered":"http:\/\/mts-help.nick.php.dev\/after_sale_support\/Working_with_Dynamic_Flash_Galleries\/article8.html"},"modified":"2013-02-01T09:11:33","modified_gmt":"2013-02-01T14:11:33","slug":"how-protect-admin-folder-with-htaccess","status":"publish","type":"post","link":"https:\/\/www.templatemonster.com\/help\/how-protect-admin-folder-with-htaccess.html","title":{"rendered":"How to protect admin folder with .htaccess"},"content":{"rendered":"<strong> <em>.htaccess<\/em> <\/strong> can be used to protect folders on your account with a password-encryption. All files and subfolders within a folder protected by <em>.htaccess<\/em> will also be protected. Thus if you want to protect the whole website you should place <em>.htaccess<\/em> to <strong>public_html<\/strong> or <strong>httpdocs<\/strong> folder which is the public folder where your website files and folders are kept. But, if you want to protect only the specific folders, you will need to do that separately for each of the folders.\r\n<strong>Note:<\/strong> If you have a Windows-based hosting plan, you cannot use .htaccess files. You can only use the .htaccess protection on the Apache-based Unix\/Linux server.\r\n<h4><strong>1. Navigate to the folder that you want to protect<\/strong><\/h4>\r\nIn the following example we would like to protect the <em>admin<\/em> folder of the <strong> <em>Dynamic Flash Gallery<\/em> <\/strong> in the <em>public_html<\/em> folder.\r\n\/users\/user1\/public_html\/admin\r\n<span style=\"font-weight: bold;\">Note:<\/span> You need to keep the full path for the folder that you would like to protect. In our case the full path is\u00a0 <em>\/users\/george\/public_html\/protected<\/em> .\r\n<strong>The remaining steps in this guide assume we are still in this folder.<\/strong>\r\n<h4><strong>2. Create a file named .htaccess<\/strong><\/h4>\r\nUse any text editor up to your choice to create a file called <em>.htaccess<\/em> (Note: the period at the beginning of the filename. Now, make sure that your text editor did not append a .txt suffix to the file name. (In Windows, you can do this by right-clicking the icon for the text file and selecting &#8220;Properties&#8221;.) If the file name does have a .txt suffix (i.e. &#8216;.htpasswd.txt&#8217;), remove the suffix by renaming the file.\r\n<h4><strong>3. Add the appropriate lines to the <em>.htaccess<\/em> file.<\/strong><\/h4>\r\n<h4><span style=\"font-weight: normal;\">Using the same text editor (you chose in step 2), input the following.<\/span><\/h4>\r\n<blockquote><span style=\"color: #0066ff;\">AuthUserFile \/users\/george\/public_html\/admin\/.htpasswd\r\nAuthName &#8220;Title for Protected Site&#8221;\r\nAuthType Basic\r\nRequire valid-user<\/span><\/blockquote>\r\n<strong>Note:<\/strong>\r\n<ol>\r\n\t<li>beside <strong>AuthUserFile<\/strong>, you should put the full path, with <em>\/.htpasswd<\/em> immediately following it. The above example shows <em>\/users\/george\/public_html\/admin\/.htpasswd<\/em><\/li>\r\n\t<li>beside <strong>AuthName<\/strong>, input the words or phrase that you wish to appear as the title for the username\/password input box.<\/li>\r\n<\/ol>\r\n<h4><strong>4. Create the <em>.htpasswd<\/em> file by adding users<\/strong><\/h4>\r\n<ol>\r\n\t<li>Open up a text editor on your computer. We recommend that you use Notepad (Windows), SimpleText (Macintosh).<\/li>\r\n\t<li>Save the file (in an easy-to-find location) as .htpasswd (including the initial dot).<\/li>\r\n\t<li>Now, make sure that your text editor did not append a .txt suffix to the file name. (In Windows, you can do this by right-clicking the icon for the text file and selecting \u201cProperties\u201d.) If the file name does have a .txt suffix (i.e. \u2018.htpasswd.txt\u2019), remove the suffix by renaming the file.<\/li>\r\n\t<li>Before entering code into your new file, make sure that \u201cWord Wrap\u201d is turned off. (In Notepad, select \u201cFormat\u2026\u201d from the top navigation bar and make sure that \u201cWord Wrap\u201d is unchecked.<\/li>\r\n\t<li>Begin by selecting the username that you will use to log-in to the protected directory. (Usernames can be between 2 and 16 characters long and should only contain lower-case letters and numbers.)<\/li>\r\n\t<li>Type the username into the .htpasswd file followed by a colon. Your file should look like this:<span style=\"color: #0066ff;\"> <span style=\"font-weight: bold;\">username:<\/span> <\/span><\/li>\r\n\t<li>You\u2019ll now need to encrypt the password that you will use to log-in to the directory. To do this, visit <a class=\"link3\" href=\"http:\/\/users.abac.com\/cgi-bin\/pass.pl\" target=\"_blank\">http:\/\/users.abac.com\/cgi-bin\/pass.pl<\/a>. On this page, enter your password (up to 13 characters) and hit the \u201cSubmit\u201d button \u2013 the encrypted password will be displayed on the following page.Note: The encrypted password will always be 13 characters long, regardless of the actual length of your password.<\/li>\r\n\t<li>Copy the encrypted password from the webpage and paste it into your .htpasswd file following the colon. Be sure to remove any spaces that may precede or follow the password. Your file should look like this:<span style=\"font-weight: bold; color: #0066ff;\">username:WvePMzyciLRIo<\/span><\/li>\r\n\t<li>To add additional users, end the current line with a carriage return and repeat <strong>steps (5)<\/strong> through <strong>(8)<\/strong> above on the next line.<\/li>\r\n\t<li>When you\u2019re done adding users, save the file.<\/li>\r\n<\/ol>\r\n<h4><strong>5. Set the permissions on your .htaccess and .htpasswd file<\/strong><\/h4>\r\nOpen your FTP and browse to the root directory of your website. This is important: uploading your <em>.htpasswd<\/em> file to another directory may cause unexpected consequences.\r\nNow set your upload settings to ASCII (Uploading <em>.htpasswd<\/em> files in \u2018binary\u2019 format may have unexpected consequences.) and upload your <span style=\"font-style: italic;\">.htaccess .htpasswd<\/span> file from your local computer. Be sure not overwrite an existing <em>.htpasswd<\/em> file \u2013 you may lose whatever login information is stored in that file.\r\n\r\n<strong>Note:<\/strong>\r\nIf you have an existing <em>.htpasswd<\/em> file in your root directory, we suggest that you add the usernames and passwords contained in that file to your new <em>.htpasswd<\/em> file before uploading it to the web. You can do this by first downloading the old <em>.htpasswd<\/em> file and copying and pasting its content into your new file.\r\nAfter the upload is completed, you may need to change the file permissions for the <em>.htaccess<\/em> and <em>.htpasswd<\/em> file. They should be set to 644 (using chmod) or RW-R&#8211;R&#8211;.\r\n<h4><strong>How do I remove htaccess protection?<\/strong><\/h4>\r\nTo remove htaccess protection, simply delete or rename the <em>.htaccess<\/em> file in the <em>admin<\/em> folder.","protected":false},"excerpt":{"rendered":"<p>.htaccess can be used to protect folders on your account with a password-encryption. All files and subfolders within a folder protected by .htaccess will also be protected. Thus if you want to protect the whole website you should place .htaccess to public_html or httpdocs folder which is the public folder where your website files and [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[282,752],"tags":[502,501,505,504],"_links":{"self":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/1875"}],"collection":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/comments?post=1875"}],"version-history":[{"count":0,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/1875\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media?parent=1875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/categories?post=1875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/tags?post=1875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}