Key takeaways
- Directory Privacy adds HTTP basic authentication to a folder.
- It's ideal for staging sites and private downloads.
- Always combine it with HTTPS so the password isn't sent in clear text.
With Directory Privacy
- In cPanel, open Files → Directory Privacy.
- Click the folder name to navigate, then Edit next to the folder you want to protect.
- Tick Password protect this directory and give it a name (shown in the login prompt).
- Click Save.
- Under Create User, add a username and a strong password, then Save.
Visiting the folder now shows a browser login box.
With .htaccess (any Apache server)
Create the password file outside the public folder:
htpasswd -c /home/username/.htpasswds/staging alice
Then add to .htaccess in the folder:
AuthType Basic
AuthName "Staging"
AuthUserFile /home/username/.htpasswds/staging
Require valid-user
Frequently asked questions
Will Google index a password-protected folder?
No. Crawlers can't log in, so protected pages aren't indexed. That makes it a good way to keep staging sites out of search results.
Can I protect WordPress's wp-admin this way?
Yes, but exclude admin-ajax.php, which some front-end features call. Many prefer two-factor login instead.