Only password protect one file in folder with .htaccess
I only want to password protect one file in开发者_Python百科 a folder. How can I do this with .htaccess?
Let's say you want to password protect your secret.html
file. Just create a .htaccess
file in the same folder as the secret file, with the following content (you may need to customize some values according to your config:
<Files secret.html>
AuthName "Login"
AuthType Basic
AuthUserFile /html/username/.htpasswd
require valid-user
</FilesMatch>
You can also use wildcards to filter some file types only. Imagine you want to password protect all zip files:
<FilesMatch "*.zip">
AuthName "Login"
AuthType Basic
AuthUserFile /html/username/.htpasswd
require valid-user
</FilesMatch>
精彩评论