การ block ผูู้ไม่ประสงค์ดีจาก User-Agent String

บางครั้งอาจมีผู้ไม่ประสงค์ดีทำการกลั่นแกล้งระบบของเราจาก IP Address ที่แตกต่างกันไป แต่ยังคงใช้ชื่อ User-Agent เดิมๆ ตลอด เราสามารถ block User-Agent ไม่ให้เข้าใช้งานได้ สำหรับการ block มี 2 แบบ คือ

1.การ Block ผู้ไม่ประสงค์ดีเพียงคนเดียว

ให้ทำการสร้างไฟล์ .htaccess และใส่ค่าดังนี้

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} BotALot [NC]
RewriteRule .* - [F,L]


หรือสามารถใช้คำสั่ง BrowserMatchNoCase ดังนี้

BrowserMatchNoCase "BotALot" bots

Order Allow, Deny
Allow from ALL
Deny from env=bots


2.การ Block ผู้ไม่ประสงค์ดีหลายคน

ให้ทำการสร้างไฟล์ .htaccess และใส่ค่าดังนี้

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^.*(Baiduspider|HTTrack|Yandex).*$ [NC]
RewriteRule .* - [F,L]


หรือ อาจใช้คำสั่ง BrowserMatchNoCase ดังนี้

BrowserMatchNoCase "Baiduspider" bots
BrowserMatchNoCase "HTTrack" bots
BrowserMatchNoCase "Yandex" bots

Order Allow,Deny
Allow from ALL
Deny from env=bots


** หมายเหตุ: กำหนดให้ “BotALot” เป็น Bad User-Agent **

Was this article helpful?

Related Articles