How would I require a password for all files except one using .htaccess?

若如初见. 提交于 2019-12-13 11:59:10

问题


I have a new website I'm working on that the client wants to keep a secret, but at the same time, I want to put an under construction page with some info on it. I would like to have everything except index.html require a user/password--index.html would be available to everyone.

I have the following, but I'm not sure what I need to add:

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /path/to/file/.htpasswd
AuthGroupFile /dev/null
require valid-user

There are too many files and possibly new files to say "for this set of files require a user/password".

I think it has something to do with something similar to:

<Files index.html>
order deny,allow
allow from all
</Files>

But I'm not exactly sure how.


回答1:


AuthName "Restricted Area"
AuthType Basic
AuthUserFile /path/to/file/.htpasswd
AuthGroupFile /dev/null

<Files "*">
Require valid-user
</Files>

<Files "index.html">
Allow from all 
Satisfy any
</Files>



回答2:


I used empi response almost exactly, but I realized that I'm loading a logo and reset-min.css on the under construction page, so I modified it like the following:

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /home/examplecom/example.com/html/.htpasswd
AuthGroupFile /dev/null

<Files "*">
Require valid-user
</Files>

<FilesMatch "(index\.html|reset-min\.css|logo-temp\.gif)$">
Allow from all
Satisfy any
</FilesMatch>



回答3:


have you tried reversing the order to first allow, then deny? For further reading: apache htaccess directive are a good reference.



来源:https://stackoverflow.com/questions/490920/how-would-i-require-a-password-for-all-files-except-one-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!