Step1)使用htpasswd建立密碼檔,在/usr/home/<username>下建立密碼檔.htpasswd
建立一個新的密碼檔,並新增使用者username,輸入密碼兩次
htpasswd -c /path/to/.htpasswd username
新增或修改使用者
htpasswd /path/to/.htpasswd username
刪除使用者
htpasswd -D /path/to/.htpasswd username
Step2)編輯受保護資料夾內的.htaccess,設定密碼與IP都需要符合才能瀏覽
AuthType Basic
AuthName "Restricted Area"
AuthUserFile <你的資料夾路徑>/.htpasswd
<RequireAll>
Require valid-user
Require ip 192.168.0.0/24 10.0.0.0/16
</RequireAll>
Step3)瀏覽http://<IP>/~<帳號>