Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to only allow one user agent on .htaccess?

I have been searching all over google and I really need to know how to only allow one user agent on .htaccess?

All I found is how to do it on a Dedicated or private server.

like image 429
Muktadir Miah Avatar asked Aug 27 '12 13:08

Muktadir Miah


People also ask

Can user agents identical?

If a different person on the Internet with the same configuration accesses your website, then their user agent will be the same.

Is user agent a string?

The User-Agent (UA) string is contained in the HTTP headers and is intended to identify devices requesting online content. The User-Agent tells the server what the visiting device is (among many other things) and this information can be used to determine what content to return.

What is the purpose of user agent string?

A browser's User-Agent string (UA) helps identify which browser is being used, what version, and on which operating system. When feature detection APIs are not available, use the UA to customize behavior or content to specific browser versions.


1 Answers

If the user-agent that you want to allow is: Lynx/2.8.8dev.12

Then you want these rules in the htaccess of the directory you want to restrict:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !Lynx/2\.8\.8dev\.12 [NC]
RewriteRule ^ - [F,L]

Every other user agent is forbidden with a 403.

like image 198
Jon Lin Avatar answered Sep 28 '22 01:09

Jon Lin