How To Password a Single File in a .htaccess
How To Password to Protect a Single File in .htaccess .htaccess can be used to limit access or protect a directory from unauthorized access on a server. With the use of a password its even more easier protecting a single file from the the rest of the accessible files by random visitors. The need of
How To Password to Protect a Single File in .htaccess
.htaccess can be used to limit access or protect a directory from unauthorized access on a server. With the use of a password its even more easier protecting a single file from the the rest of the accessible files by random visitors. The need of a password is triggered by difficulties in files movement due to site coding especially in WordPress or in Website builder and also difficulties in creating a sub-folder in the directory. .htaccess gives you the privilege of keeping your file in the primary location but protected with a password which has a specific name known to you or your desired group of people.
Below is how to create a password to protect a single file in .htaccess;
Create a desired username and a strong password that is encrypted from an external site. Use the htaccess tools and it will give you a code that will be used later in the cpanel. Ensure the file begins with a(htpassword) then place it in your root directory or save it somewhere.
Login to cpanel
Click on file manager of the hosting account. When the directory is searched through URL it cannot be accessible and this means more security.
Create a new file and ensure the show hidden files found in the settings is checked.
look for the file you created in the directory by clicking on search
Right click on it to edit the file
place the code there and ensure it stays as a single line then click save changes.
Go to public-html, – .htaccess and right click to edit. This must be on your domain.
Place this code; **AuthUserFile /home/user/.htpassword
require valid-user
AuthName “name of login prompt”
AuthType basic
This ensures that the user is prompted to login
Change the path to read as you would want, maybe replace the password or username with your own
Click Save
Was this article helpful?