Htaccess is the short form of hypertext access. It’s a configuration file used by apache-based web servers. In this article, I will show you how to htaccess password protect file with htaccess directory from your cPanel.
htaccess file can be used to perform some important function.
- deny access from specific IP address.
- prevent directory listing
- redirect visitors to another page
- htaccess password protect file.
In this article, I will show you how to protect with password your website’s file using the htaccess directory.
So to show you how to protect a specific folder using the htaccess file I will go to the Cpanel of my web hosting server and enter the File/File manager option from there.
My website is located in the public_html directory. So, I will open this directory.
Process of .htaccess password protect file
after opening the directory, I can see all the file of my website
Ok now let’s create the folder here which I want to protect. To do that I will click in the folder from the left corner and put the name for the directory.
In my case , I will put the name ‘protect’ and click create new folder to htaccess password protect file.
After creating the directory, you need to open the directory and create some important files.
So, I will create a new file called .htaccess and click ok.
this dot means that it’s a hidden file.
what’s done with that I will create another file called ABC.
This ABC file will be used to store the username and password which I will use to access the folder.
So to create the username and password for I will use a website to htaccess password protect file.
Click here to go to this website
After going this website please enter a username and password and press ‘Create htpasswd file’ button.
As you click this button you will find a generated code. You need to copy this code
after copying this text go to the ABC file which you created before. And use right click on the ABC file and click to Edit option. When you click to edit option you will find a page where you can put any text or code. which you copied from the website paste it here and click save changes to htaccess password protect file.
Once you have pasted the text go and open the .htaccess file by clicking edit and then put the following
AuthType Basic AuthName "Password Protected Area" AuthUserFile ABC file lacation Require valid-user
If you don’t understand what location of file is then go to the ABC file and edit option .You will see the location of this file here.like this- just copy this text and put it after AuthUserFile from .htaccess file editor.
In my case, I have copy this text from above and go to the .htaccess file and put this code with ABC file location by clicking edit option like this-
Ok ! You are all done to get htaccess password protect file. Now to check this open the chrome browser and type www.yourwebsite.com/protect
you can see the login box has appeared where you need to put the username and password to access the folder which you have stored in the ABC file.
After typing username and password click sign in to access this folder
So, you are successfully protecting your folder/directory with a password. So, that’s it for now and thanks for staying with primomate.com
If you guess any problem,comment in the comment box below.