I tried all of the suggestions on this page (Using .htaccess to redirect obsolete browsers) but none work. I've googled but did not find a working example.
None of these work when dealing with browsers with two digit version numbers.
For example, the line below blocks Opera v.1.x and Opera v.12.x:
RewriteCond %{HTTP_USER_AGENT} "Opera/1\." [NC,OR]
The codes below do not work either:
RewriteCond %{HTTP_USER_AGENT} "Opera/[1-11]\." [nc,or]
RewriteCond %{HTTP_USER_AGENT} "Opera/[1-9][0-1]?\." [nc,or]
What's the correct code to redirect Opera versions 1.x-11.x?
I did some more testing and found something that is odd to me. If I try to access the site with Opera version 11, the rewrite rule reluctantly kicks in when using the following:
RewriteCond %{HTTP_USER_AGENT} "Opera/9\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/8\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/7\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/6\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/5\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/4\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/3\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/2\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/1\." [NC,OR]
If I simply comment out...
RewriteCond %{HTTP_USER_AGENT} "Opera/9\." [NC,OR]
...the Opera browser version 11 does not get redirected.
To be more specific, I'm trying to redirect certain browsers with certain versions to a particular page if they match the rules. Here is a sample but it does not work as intended and I think there's got to be a more concise way to write each condition:
<ifmodule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "Firefox/3\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Firefox/2\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Firefox/1\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/9\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/8\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/7\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/6\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/5\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/4\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/3\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/2\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/1\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "MSIE 7\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "MSIE 6\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "MSIE 5\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "MSIE 4\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "MSIE 3\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "MSIE 2\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "MSIE 1\." [NC]
RewriteRule . http://www2.mysite.com/page.php [L]
</ifmodule>
Here's what I'm trying to do:
<ifmodule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "Firefox/if less than version 3\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/if less than version 10.1\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "MSIE if less than version 7\." [NC]
RewriteRule . http://www2.mysite.com/page.php [L]
</ifmodule>
The code below does what I want:
<ifmodule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "Firefox/[1-3]\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Opera/9\..*Version/(1[10]|[1-9])\. [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Opera/[1-8]\." [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "MSIE [1-7]\." [NC]
RewriteRule . http://www2.mysite.com/page.php [L]
</ifmodule>
Thank you Jon Lin! Your code suggestions helped me to understand a little better :)