Forum Moderators: phranque

Message Too Old, No Replies

htaccess browser detector?

htaccess and web browsers

         

Blue_Wizard

9:47 pm on Jun 23, 2006 (gmt 0)

10+ Year Member



I found this code in another post here.
It seems to work excellently on my site.
However, for the life of me cannot figure out how to add Opera and Firefox as valid/allowed user agents
that allow all the versions of those two browsers to work.
any suggestions
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT}!^Mozilla/[3-9]\.[0-9]\ \(compatible\;\ MSie
RewriteCond %{HTTP_USER_AGENT}!^Mozilla/4\.[0-9]{1,2}\ \[en\]
RewriteCond %{HTTP_USER_AGENT}!^Mozilla/[5-9]\.[0-9]\ \([^\)]*\)\ Gecko/[^\ ]*\ Netscape/
RewriteRule .* - [F]

someone had suggested the following two lines
RewriteCond %{HTTP_USER_AGENT}!^Mozilla/[1-9]\.[0-9]\ \([^\)]*\)\ Gecko/[^\ ]*\ Firefox/
RewriteCond %{HTTP_USER_AGENT}!^Mozilla/[1-9]\.[0-9]\ \([^\)]*\)\ Gecko/[^\ ]*\ Opera/

but I was certain that Firefox and Opera are built on Mozilla/Gecko

Blue_Wizard

9:48 pm on Jun 23, 2006 (gmt 0)

10+ Year Member



typo that should read
but I was NOT certain that Firefox and Opera are built on Mozilla/Gecko

jdMorgan

1:50 pm on Jun 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a browser-section excerpt from some code I've used:
# Mozilla 4/5 Browsers
RewriteCond %{HTTP_USER_AGENT} !^Mozilla/[4-5]\.[0-9]+\ \(compatible;\ MSIE\ [3-9]\.[0-9.]+
RewriteCond %{HTTP_USER_AGENT} !^Mozilla/[4-5]\.[0-9]+\ \(Macintosh;\ .+\)\ \AppleWebKit/[1-9]\.[0-9.]+\ \(KHTML,\ like\ Gecko\)\ \Safari/[0-9]{3,8}$
RewriteCond %{HTTP_USER_AGENT} !^Mozilla/[4-5]\.[0-9]+\ \(Macintosh;\ I;\ PPC\)$
RewriteCond %{HTTP_USER_AGENT} !^Mozilla/[4-5]\.[0-9]+\ \(X11;\ U;\ Linux\ i686;\ [a-z]{2}-[A-Z]{2};\ rv:[1-9]\.[0-9.]+\)\ Gecko/Debian-[1-9]\.[0-9.]+-[0-9]+\ Galeon/[2-9]\.[0-9.]+\ \(Debian\ package\ [2-9]\.[0-9.]+-[0-9]+\)$
RewriteCond %{HTTP_USER_AGENT} !^Mozilla/[4-5]\.[0-9]+\ \(compatible;\ Konqueror/([0-9]+\.)+[0-9]+.+\ 20[0-9]{6}\)$
RewriteCond %{HTTP_USER_AGENT} !^Mozilla/[4-5]\.[0-9]+\ \(compatible;\ Konqueror/([0-9]+\.)+[0-9]+;\ Linux\)\ \(KHTML,\ like\ Gecko\)$
RewriteCond %{HTTP_USER_AGENT} !^Mozilla/[4-5]\.[0-9]+\ \(.+;\ rv:([0-9]+\.)+[0-9a-z]+\)\ Gecko/20[0-9]{6}
RewriteCond %{HTTP_USER_AGENT} !^Mozilla/[4-5]\.[0-9]+\ WebTV/([0-9]+\.)+[0-9]+\ \(compatible;\ MSIE\ [5-9]\.[0-9]+
# Others
RewriteCond %{HTTP_USER_AGENT} !^Avant\ Browser\ \(http://www\.avantbrowser\.com\)$
RewriteCond %{HTTP_USER_AGENT} !^Microsoft\ Internet\ Explorer/[34]\.[0-9]{1,2}
RewriteCond %{HTTP_USER_AGENT} !^Mozilla/(3\.01¦4\.0)\ \(compatible;\)$
RewriteCond %{HTTP_USER_AGENT} !^Mozilla/[3-4]\.[0-9]+\ \[[a-z]{2}\](\ \(.+\))?
RewriteCond %{HTTP_USER_AGENT} !^Mozilla/4\.0\ \(PSP\ \(PlayStation\ Portable\);\ [0-9.]+\)$
RewriteCond %{HTTP_USER_AGENT} !^Opera/[5-9]\.[0-9]+
RewriteRule .* - [F]

Be aware that by using a browser-only list, you'll block search engine spiders, media players, mobile devices and their HTL-to-WML-or-WAP translation proxies, and web content filters (which may block your site as a result).

Sorry about the line-wrap on Gecko/Debian for Linux; It's the longest UA I've ever seen. Its first line ends with "\ ", that is, backslash space, so make sure those characters precede the "Gecko/Debian" when you paste the lines back together.

Jim