zencart通過(guò)密碼保護(hù)網(wǎng)站文件、目錄,限制
下面提到的 AuthUserFile /home/path/.htpasswd ,用于指定密碼文件.htpasswd, 該文件需要手工建立。 宇塵網(wǎng)絡(luò)幫助中心域名知識(shí)|虛擬主機(jī)知識(shí)|VPS主機(jī)知識(shí)|服務(wù)器知識(shí)|網(wǎng)站建設(shè)知識(shí)|網(wǎng)絡(luò)推廣
/home/path 是用于存放 .htpasswd 文件的目錄,相應(yīng)修改。
Google下能找到很多相關(guān)說(shuō)明,也可以在線(xiàn)生成 .htpasswd 密碼文件,例如:
這些代碼需要保存到 .htaccess 文件,并置于需要保護(hù)的目錄下,例如zencart網(wǎng)店的admin目錄下。
基本的密碼保護(hù)方法:
代碼: 全選
# basic password protection
<IfModule mod_auth.c>
AuthUserFile /home/path/.htpasswd
AuthName “Username and password required”
AuthType Basic
<Limit GET POST>
Require valid-user
</Limit>
</IfModule>
僅某些IP可以訪問(wèn),其它的需要輸入密碼:
代碼: 全選
# password protect excluding specific ips
<IfModule mod_auth.c>
AuthName “Username and password required”
AuthUserFile /home/path/.htpasswd
AuthType Basic
Require valid-user
Order Deny,Allow
Deny from all
Allow from localhost
Allow from 111.222.333.444
Allow from 555.666.777.888
Satisfy Any
</IfModule>
僅某些IP段的用戶(hù)訪問(wèn)需要密碼,其它IP的用戶(hù)無(wú)需密碼:
代碼: 全選
# password protect only for specified ips
<IfModule mod_auth.c>
AuthName “Username and password required”
AuthUserFile /home/path/.htpasswd
AuthType Basic
Require valid-user
Order Allow,Deny
Allow from all
Deny from 111.222.333.444
Deny from 555.666.777.888
Satisfy Any
</IfModule>
密碼保護(hù)單個(gè)文件:
代碼: 全選
# password protect single file
<IfModule mod_auth.c>
<Files “protected.html”>
AuthName “Username and password required”
AuthUserFile /home/path/.htpasswd
Require valid-user
AuthType Basic
</Files>
</IfModule>
其中 protected.html 是需要輸入密碼才能訪問(wèn)的文件。
密碼保護(hù)多個(gè)文件:
代碼: 全選
# password protect mulitple files
<IfModule mod_auth.c>
<FilesMatch “(protected.html)|(passwords.txt)”>
AuthName “Username and password required”
AuthUserFile /home/path/.htpasswd
Require valid-user
AuthType Basic
</FilesMatch>
</IfModule>
上面指定 “protected.html” 和 “passwords.txt” 文件需要密碼才能打開(kāi)。同樣可以加上更多的文件。 仿牌空間、香港月付空間、韓國(guó)月付空間、日本月付空間、荷蘭VPS、香港VPS
密碼保護(hù)多種文件類(lèi)型:
代碼: 全選
# password protect mulitple file types
<IfModule mod_auth.c>
<FilesMatch “.(inc|txt|log|dat|zip|rar)$”>
AuthName “Username and password required”
AuthUserFile /home/path/.htpasswd
Require valid-user
AuthType Basic
</FilesMatch>
</IfModule>
這樣就密碼保護(hù)了這些類(lèi)型的文件:.inc, .txt, .log, .dat, .zip, .rar。
密碼保護(hù)除了某個(gè)文件外的所有文件:
代碼: 全選
# password protect everything except a single file
<IfModule mod_auth.c>
AuthName “Username and password required”
AuthUserFile /home/path/.htpasswd
Require valid-user
AuthType Basic
<Files “open-access.html”>
Order Deny,Allow
Deny from all
Allow from 123.456.789
Satisfy any
</Files>
</IfModule>
這樣就只有訪問(wèn) open-access.html 這個(gè)文件不需要密碼,該文件可以是保存在某個(gè)子目錄中。 美國(guó)月付空間、月付美國(guó)空間、美國(guó)VPS、美國(guó)服務(wù)器租用
密碼保護(hù)除了某些文件外的所有文件:
代碼: 全選
# password protect everything except specified files
<IfModule mod_auth.c>
AuthName “Username and password required”
AuthUserFile /home/path/.htpasswd
Require valid-user
AuthType Basic
<FilesMatch “(open-access-1.html)|(open-access-2.html)|(open-access-3.html)”>
Order Deny,Allow
Deny from all
Allow from 123.456.789
Satisfy any
</FilesMatch>
</IfModu
更多技術(shù)知識(shí),更多網(wǎng)絡(luò)服務(wù),盡在宇塵網(wǎng)絡(luò)。我們的成長(zhǎng),離不開(kāi)你們的支持,宇塵網(wǎng)絡(luò),歡迎您的訪問(wèn)。