How to Password-Protect a Website or Folder (Plesk and .htaccess)
Lock a site before launch or a private folder behind a login. Step-by-step for Plesk, .htaccess and Nginx, plus how to test it and what it does not protect.
To password-protect a website or a single folder, you put a username and password in front of it at the web server level. Before any page loads, the browser asks for the login, and without it visitors see nothing. On a Plesk plan, this takes a few clicks. Without Plesk, you create two small files, .htaccess and .htpasswd. This guide covers both ways, how to test the result, and what this kind of lock does not protect.
When a password on the whole site or a folder makes sense
This lock is called HTTP basic authentication: a simple login box the web server shows before it sends any page. It suits short-term, low-risk privacy, for example:
- A new site before launch. A shop in Prishtina can let its team click through the new pages while the old site stays live.
- A draft for review. A law office in Skopje can check the wording of its new site without strangers or search engines seeing it.
- A private folder. Price lists, press kits or files for one partner, shared with a link and a login.
A noindex tag only asks search engines not to list a page. A password stops them, and everyone else, from reading it at all.
The easy way: password-protected directories in Plesk
If your site runs on Plesk, you do not need to touch any files.
- Log in to Plesk and open Websites & Domains.
- Find your domain and look for Password-Protected Directories. Names can vary by Plesk version.
- Click Add Protected Directory and enter the folder name, for example
preview. Protecting a folder also protects every folder inside it. - Give the protected area a title if you like. Some browsers show it in the login box. Click OK.
- Click the folder in the list, choose Add a User, and enter a username and a strong password. Until you add a user, nobody can get in.
To lock the whole site, ask our support which entry your Plesk version expects, or use the manual method below.
Create one user for each person who needs access. When a freelancer finishes, you delete their user and everyone else keeps working.
The manual way: .htaccess and .htpasswd
.htaccess is a small settings file that the Apache web server reads in each folder. .htpasswd holds the usernames and their passwords in hashed form, which means scrambled one way, so the real password is never stored. These rules work where Apache serves the site. If you are not sure what serves yours, our support can confirm it for your plan.
Step 1: create the password file
If you have a command line with the htpasswd tool, run:
htpasswd -c -B /path/outside/public-folder/.htpasswd annaIt asks for the password twice. -c creates a new file, so use it only for the first user, because running it again replaces the file. -B uses bcrypt, a strong hashing method. For a second user, run the same command without -c.
No command line? An htpasswd generator website can make the line for you. Choose one you trust, pick bcrypt, and never enter a password you use anywhere else.
Step 2: add the rules
Put these lines in a file named .htaccess inside the folder you want to protect. For the whole site, use the site's top folder.
AuthType Basic
AuthName "Private preview"
AuthUserFile /path/outside/public-folder/.htpasswd
Require valid-userAuthUserFile needs the full path to your password file on the server. If you do not know it, ask our support. On WordPress, add these lines above the # BEGIN WordPress block, because WordPress rewrites everything between its own markers.
On a VPS with Nginx
Nginx, another popular web server, ignores .htaccess files. On a VPS with full root access, create the password file with the same htpasswd command, from the apache2-utils package on Ubuntu and Debian or httpd-tools on AlmaLinux. Then add the rule to your site's server block:
location /preview/ {
auth_basic "Private preview";
auth_basic_user_file /etc/nginx/.htpasswd;
}Check the settings with sudo nginx -t, then apply them with sudo systemctl reload nginx.
Test it, and fix it when the prompt does not appear
Open the address in a private browser window, so no saved login gets in the way. You should see a login box. You can also check from a terminal:
curl -I https://example.com/preview/The first line of the response should show 401, which means the server wants a login. Add -u anna to the command, type the password when asked, and you should get 200, which means the page loaded.
| Problem | Likely cause | What to do |
|---|---|---|
| No login box at all | A saved login, or a web server that ignores .htaccess | Try a private window, then ask support which server handles your site |
| Error 500 after adding the rules | A typo or a wrong AuthUserFile path | Check each line and the full path |
| The box keeps coming back | The username or password does not match the file | Reset the user's password and type it carefully |
What basic password protection does not protect
Basic authentication is a gate, not a vault.
- It needs HTTPS. The browser sends the login with every request, encoded but not encrypted. Only use it on addresses that start with https://. Every domain with us gets free SSL.
- It does not stop guessing on its own. Use a long, unique password.
- It is not for customer data. Payment details and personal records need proper accounts, permissions and encryption.
- It only covers web addresses. Files someone already downloaded stay with them.
On WordPress, locking the whole site can also block its own background tasks, and Site Health may report loopback errors (WordPress failing to reach itself). That is expected; remove the lock when you launch. For the other layers that protect a site, see our security page.
Keeping private pages private with Zebra Hosting
Our shared, WordPress and reseller plans come with Plesk, so you can add a protected folder in a few clicks. Free SSL on every domain renews automatically, which keeps every login encrypted. If the login box does not behave, open a ticket, send an email or call us. Tickets are answered in 17 languages, including Albanian, Macedonian and Serbian. See our shared hosting plans to find the one that fits your site.