In this guide, we explain how you can protect your website - or a specific file or directory - with a password, so only authorised users can access it.
- Step 1 - Open File Manager in the one.com Control Panel
- Step 2 - Generate the .htaccess and .htpasswd files
- Step 3 - Paste the configuration in the existing .htaccess file (optional)
- Step 4 - Create a username and password
- Step 5 - Adjust the .htaccess configuration to protect a specific file (optional)
- Step 6 - Done!
Step 1 - Open File Manager in the one.com Control Panel
- Log in to the one.com Control Panel.
- Click File Manager on the Files & Security tile.
Step 2 - Generate the .htaccess and .htpasswd files
You need to generate the files at the location that you want to protect. So, if you want to protect your entire site, stay in the main directory. If you're going to protect a single file or folder, you need to go to that directory.
- Go to the directory (folder) you want to protect with a password.
- Click the downwards arrow next to the + Upload button and select Secure directory.
Step 3 - Paste the configuration in the existing .htaccess file (optional)
Note: You only need to follow this step if you already have an existing .htaccess file.
- Copy the lines provided in the middle of your screen.
- Select the .htaccess file and click Edit.
- Paste the configuration at the top, above the existing rule(s).
- Click Save at the top of your screen.
Step 4 - Create a username and password
You can create as many logins as you need, and you can also remove them again. The username can only contain letters and numbers.
- Select the file called .htpasswd.
- Click the large file icon to the right on your screen.
- Enter a username and password. Remember to save the password somewhere else.
- Click Save.
Tip: If you don't remember the password, you can simply remove the existing user by clicking the "x" next to the user, and then create it again.
Step 5 - Adjust the .htaccess configuration to protect a specific file (optional)
Follow these steps to adjust the .htaccess configuration so that it only protects a single file and not the entire directory.
- Select the .htaccess file and click Edit.
- Adjust the code by adding the following lines at the top and the bottom, replacing "file-name-here" with the file you want to protect:
<Files "file-name-here">
<--- existing code --->
</Files>
- Click Save at the top of your screen.
Step 6 - Done!
When you open your website in your browser, you will now see a login screen asking for the username and password.
Related articles: