Wednesday, August 11, 2010

[Unix] htacess

1. สร้าง .htaccess ไฟล์

shell#vi .htaccess
แล้วกำหนดค่าต่างๆ ที่จะใช้
AuthUserFile {path to .htpasswd file}
AuthGroupFile {path to .htgroup file}
AuthName {title for dialog box}
AuthType Basic

ตัวอย่าง

AuthUserFile .htpasswd
AuthName "My Private Directory"
AuthType Basic

require user liingz
require group admin


2. สร้าง .htpasswd

สร้างไฟล์ htpasswd ตามคำสั่งด้านล่างนี้
Shell#htpasswd -c .htpasswd username


หากต้องการเพิ่ม User หรือเปลี่ยนรหัสของ User ที่มีอยู่เดิม ใช้คำสั่งดังนี้
Shell#
htpasswd .htpasswd newuser/username


3. ทำการตั้งค่าที่ Apache Configuration ให้สามารถใช้ .ht ได้
เขียน AllowOverride All ในส่วนของ Directory Path ที่จะใช้ .htaccess
และ
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
< Directory Path >
AllowOverride All
Order allow,deny
Deny from all
Satisfy All
< /
Directory Path >
หลังจากนั้น Restart Apache



No comments:

Post a Comment