這個參數是在要做驗證的目錄的配置段下將:
AllowOverride None
改爲:
AllowOverride All
二、增加用戶以及設置密碼。
/usr/local/apache2/bin/htpasswd -c /usr/local/apache2/conf/htusers username
注1:/usr/local/apache2/conf/htusers這個文件是用戶帳戶文件,這個命令後會讓你輸入兩次密碼做爲你建的這個用戶的密 碼。
注2:/usr/local/apache2/bin/htpasswd這個因你的apache安裝目錄而定。
三、在要做驗證的目錄下,編輯.htaccess文件:
vi /home/www/html/authFile
AuthName “Please input Username and Pasword:”
AuthType Basic
AuthUserFile /usr/local/apache2/conf/htusers
require valid-user
四、重啓Apache,然後測試:
#/etc/init.d/apache2 restart
在瀏覽器上輸入URL,如果有彈出需要用戶名和密碼的對話框,使用上面創建的用戶名和密碼可以正常打開的話。
恭喜你,你成功了。
The end.