Knowledge Base
MilesWeb / cPanel

Learn to Block a User Agent in a .htaccess File

Approx. read time : 2 min

If there is high traffic on your website from different IP addresses with one and the same User Agent, you can restrict them by blocking. For this, you need to edit your .htaccess file and add the below rules:

Here replace UserAgentName with the actual name of the User Agent. For example, for blocking a User Agent named Textbot, you should add the below code:

Add them at the start of the .htaccess file. For blocking more than one User Agent (e.g. named SCspider, Textbot and s2bot), add the below code:

For blocking the requests from machines with missing User Agent, add the below rules in your .htaccess file:

In this way, you can clock a User Agent in an .htaccess file.

Also Read:
How To Change Document Root Using .htaccess File?
Steps to Enable Password Protection for .htaccess

Avatar
Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.
Need help? We’re always here for you.
Register Your Free Domain Name
OFFER EXPIRES IN
04
min
59
sec