Forum Moderators: phranque
RewriteCond %{HTTP_USER_AGENT} Firefox/1 [OR]
RewriteCond %{HTTP_USER_AGENT} Firefox/2
RewriteRule .* http://www.example.com/ [R=301,L]
Note that Camino declares itself to be "like Firefox".
You may find this recent discussion of Gecko browsers useful:
[webmasterworld.com...]
...
If you only want version 3.0.4 to get through then you could do something like:
# If user-agent contains Firefox
RewriteCond %{HTTP_USER_AGENT} Firefox
# and is not Firefox 3.0.4
RewriteCond %{HTTP_USER_AGENT} !Firefox/3\.0\.4
# redirect elsewhere
RewriteRule .* http://www.example.com/ [R=301,L]
The problem with this approach is future-proofing - expect 3.0.5 anytime soon.
Perhaps if you explain why you are doing this we can offer other suggestions.
...
i want to direct visitor with old firefox browser to landing to my spreadfirefox affiliate page..
no problem if i need to update the the htaccess again if firefox have a new version..
btw, this is just for my knowledge.. how if i also want to allow firefox which useragent that have space in it (example: "Firefox Beta/3.0.4") also?
is the code will look like this?
RewriteCond %{HTTP_USER_AGENT} firefox [NC,OR]
RewriteCond %{HTTP_USER_AGENT} !firefox 3\.0\.4^ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} !firefox Beta 3\.0\.4^ [NC]
RewriteRule .* http://www.example.com/ [R=301,L]
btw, is it a must to include "\" before dot?
[edited by: Mystique at 12:42 pm (utc) on Nov. 16, 2008]
You need to lose the "hat" symbol (^) which means "starts with".
Real Firefox (as far as I am aware) always starts with a capital, so [NC] is redundant if you use one.
You would also need to escape any spaces or parentheses:
RewriteCond %{HTTP_USER_AGENT} !Firefox\ Beta/3\.0\.4\ \(Whatever\)
That said, you need to have a pretty comprehensive knowledge of likely user-agents - the early releases of major versions often have codenames (Minefield, GranParadiso etc) and don't mention Firefox at all, and there are numerous other Gecko browsers that share a lot of the Firefox code which you will also not catch.
I would advise reading up on .htaccess basics in the forum library before getting too deeply into this.
If you are just trying to intercept any Firefox below version 3.0.4 you might be better off with a scripting solution that allows "less than" comparisons - I don't think this is possible in .htaccess (though if it is then one of the experts here will probably correct me).
...
why when i try he code above i got 500 internal server error?
Possibly because I didn't explain clearly enough.
But you have a superfluous OR, a misplaced hat, an escape and an [NC] you don't want as well.
I would advise reading up on .htaccess basics in the forum library before getting too deeply into this
This is powerful stuff - one misplaced character and your site is offline.
Other items in your .htaccess sometimes cause conflicts, and you will probably require these:
Options +FollowSymlinks
RewriteEngine On
...before you invoke any mod_rewrite conditions and rules.
Hope this helps.
...
# If not Camino
RewriteCond %{HTTP_USER_AGENT} !Camino/
# and if not Netscape
RewriteCond %{HTTP_USER_AGENT} !Netscape/
# and if Firefox
RewriteCond %{HTTP_USER_AGENT} Firefox/([0-9](\.[0-9]+)+)
# and if Firefox version is lexically less than "Firefox/3.0.4"
RewriteCond %1 < "3.0.4"
# and if not currently requesting "old firefox" page
RewriteCond %{REQUEST_URI} !^/oldfirefoxpage\.html$
# Then redirect page requests (only) to "old Firefox" page
RewriteRule \.(html?Šphp)$ http://www.example.com/oldfirefoxpage.html? [R=302,L]