How to protect a folder in your website with .htaccess ?
You can protect a folder or your entire website with username and password. You can block all the unwanted users from accessing your protected folder or website. Create a file named .htaccess and place it in the folder you want to protect. In this example I will protect the entire website and I will place the file in /var/www/yourwebsite.com/public_html/.htaccess.
This is the content of the file .htaccess:
1 2 3 4 5 | AuthUserFile "/var/www/yourwebsite.com/.htpasswd" AuthGroupFile /dev/null AuthName "Private Area" AuthType Basic require valid-user |
Now type:
1 | username:generated_password |
Now type:
1 2 3 4 5 | <Directory /var/www/yourwebsite.com/public_html/> ... AllowOverride AuthConfig ... </Directory> |
Finally reload the apache:
Leave a Reply