htaccess config to block depending on browser agent
how is the opposite done of this code ?
for example inhibition of ^.Chrome/10.$
entry
htaccess config to block depending on browser agent
how is the opposite done of this code ?
for example inhibition of ^.Chrome/10.$
entry
The answer you linked to contains the following code:
RewriteCond %{HTTP_USER_AGENT} ^.*Chrome/10.*$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^.*Firefox/4.*$
RewriteRule .* - [L]
RewriteRule .* http://example.com/browsererror.html [R,L]
This allows requests from user agents that match the pattern ^.*Chrome/10.*$
or ^.*Firefox/4.*$
. It does this by essentially doing nothing (- [L]
) when these requests reach your site and redirecting otherwise.
To do the exact opposite and block requests from these user agents by redirecting then just remove the second RewriteRule
and redirect in the first:
RewriteCond %{HTTP_USER_AGENT} ^.*Chrome/10.*$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^.*Firefox/4.*$
RewriteRule .* http://example.com/browsererror.html [R,L]
However, this isn't necessarily the "best way" to block requests from specific user-agents. Instead of using mod_rewrite, consider using mod_setenvif and the appropriate mod_authz... module (depending on whether you are on Apache 2.2 or 2.4). And serve a 403 Forbidden instead of redirecting. For example: