how can I use .htaccess to "require" firefox usera

Need technical advice on coding your web pages? Covers HTML, JavaScript, CSS, and some server side technologies. Also the issue of some webpages not displayed well.

Moderator: Don_HH2K

how can I use .htaccess to "require" firefox usera

Postby sargon » Thu 03 Mar, 2005 12:10 am

Rather than create an extensive set of blocks based on user agent I'd rather have "block if not firefox". This is not a commercial application or even large scale so I'm not worried about profit loss or alienation. :)

This doesn't work to redirect IE to getfirefox either

Code: Select all
RewriteEngine on
RewriteOptions MaxRedirects=2
RewriteBase /
RewriteCond %{USER_AGENT}  "MSIE"
RewriteRule ^.*$    http://getfirefox.com [L,NC]


Anyone have some constructive advice?


thanks mucho
UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050225 Firefox/1.0.1 (MOOX M3)
GetFirefox
sargon
new member
new member
 
Posts: 3
Joined: Wed 02 Mar, 2005 11:58 pm

Re: how can I use .htaccess to "require" firefox u

Postby Antony » Thu 03 Mar, 2005 12:32 am

sargon wrote:Rather than create an extensive set of blocks based on user agent I'd rather have "block if not firefox". This is not a commercial application or even large scale so I'm not worried about profit loss or alienation. :)
That can be easily done, but might to too harsh.
Plus you might block a huge number of Firefox (or Mozilla) users who just enjoy faking useragnets.

Firstly, there were a few errors in your code.
The flag [tt][NC][/tt] is for no case, and you should put it in [tt]RewriteCond[/tt] line.
and you need [tt][R][/tt] to redirect in the [tt]RewriteRule[/tt]

I would suggest you apply RegExp (Regular Expression) to match non-Firefox, it depends on which way you want. But simple "MSIE" won't match anything.

Finally, its [tt]{HTTP_USER_AGENT}[/tt].

Redirect to a polite message page would be better than sending to getfirefox.com straight away.
UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.5.6 (KHTML, like Gecko) Safari/125.12
User avatar
Antony
diamond member
diamond member
 
Posts: 14509
Joined: Tue 18 Jun, 2002 11:36 pm
Location: Sydney, Australia

Re: how can I use .htaccess to "require" firefox u

Postby sargon » Thu 03 Mar, 2005 1:20 am

First thank you for your reply.

Antony wrote:Plus you might block a huge number of Firefox (or Mozilla) users who just enjoy faking useragnets.
The site in question will be used by at most 28 people so I'm not too worried about it. I'm really tired of dealing with IE issues with people who know they're supposed to be using firefox. So if it's not firefox they'll be chided rather than redirected to getfirefox.

The flag [tt][NC][/tt] is for no case, and you should put it in [tt]RewriteCond[/tt] line.
and you need [tt][R][/tt] to redirect in the [tt]RewriteRule[/tt]


how about

Code: Select all
RewriteEngine on
RewriteOptions MaxRedirects=2
RewriteBase /
RewriteCond %{HTTP_USER_AGENT}  !^Mozilla/5.0 [NC]
RewriteRule ^.*$    /errors/firefox.shtml  [L]


the .htaccess within /errorrs/ will have a rule negating the root check

Code: Select all
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_USER_AGENT}  !^Mozilla/5.0 [NC]
RewriteEngine off



I would suggest you apply RegExp (Regular Expression) to match non-Firefox, it depends on which way you want.
Regular expressions frighten me. OK, not really, but I'm not proficient. I go about as far as copy paste with spamassassin rules. I know "^startswith" and "endswith$" but I'm not too clear about "!" for "isnot".


Finally, its [tt]{HTTP_USER_AGENT}[/tt].
yeah I caught that when I did a bit more reading. thanks :)


Thank you for your help


cheers
UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050225 Firefox/1.0.1 (MOOX M3)
GetFirefox
sargon
new member
new member
 
Posts: 3
Joined: Wed 02 Mar, 2005 11:58 pm

Re: how can I use .htaccess to "require" firefox u

Postby Antony » Thu 03 Mar, 2005 2:10 am

sargon wrote:how about
...
I would use
Code: Select all
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT}  !^Mozilla/5.0.*$ [NC]
RewriteRule ^(.+) /errors/firefox.shtml  [R,L]


the [tt].*$[/tt] at end would match any string, and [tt][R][/tt] would perform a redirection.

I am not 100% sure what [tt]RewriteOptions MaxRedirects=2[/tt] and [tt]RewriteBase /[/tt] do.

the .htaccess within /errorrs/ will have a rule negating the root check
Good idea, I don't think it's necessary (straight out from my mind)

You should test if the blocking of non-Firefox works or not yourself.

sargon wrote:
I would suggest you apply RegExp (Regular Expression) to match non-Firefox, it depends on which way you want.
Regular expressions frighten me. OK, not really, but I'm not proficient. I go about as far as copy paste with spamassassin rules. I know "^startswith" and "endswith$" but I'm not too clear about "!" for "isnot".
I know Regular expressions are scary. I need to check that up each time I use. [tt]![/tt] works for "not".
UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.5.6 (KHTML, like Gecko) Safari/125.12
User avatar
Antony
diamond member
diamond member
 
Posts: 14509
Joined: Tue 18 Jun, 2002 11:36 pm
Location: Sydney, Australia

Postby ryaxnb » Fri 18 Mar, 2005 4:11 pm

Be fair - Kill no one. Allow every standards-compliant browser to your site.
That means no IE 4, 5, 6, Netscape 1, 2, 3, 4, OmniWeb 1-4.1.
But allow Netscape 6, 7, 8, Mozilla (all versions,) Firefox and Camino (all versions,) Opera, anything with KHTML in the user agent string (Safari, OmniWeb 4.5+, and Konqueror, for instance, anything with Gecko in there (Epiphany, Galeon,) and iCab, for at least trying, albeit failing miserably, to support standards.
UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/125.4 (KHTML, like Gecko, Safari) OmniWeb/v563.34
Trainable is to cat as ability to live without food is to human.
ryaxnb
senior member
senior member
 
Posts: 92
Joined: Thu 13 Nov, 2003 2:07 am
Location: Felton, CA

Postby Pu7o » Wed 23 Mar, 2005 9:17 am

i think what you should block is "Mozilla/4", not "just allow Mozilla/5"... because if you only allow mozilla/5, how is opera ever gonna get in there? ;)

also you should check for "opera" in mozilla/4 useragents, since opera by default spoofs itself as msie...
UserAgent: Opera/8.0 (X11; Linux i686; U; en)
User avatar
Pu7o
Macfox
Macfox
 
Posts: 2014
Joined: Thu 06 Jan, 2005 12:03 pm
Location: Portugal

Postby sargon » Tue 19 Apr, 2005 2:31 am

thanks!! "*$" helped tons.

Code: Select all
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT}  !^Mozilla/5.0.*$ [NC]
RewriteRule ^(.+) /errors/firefox.shtml  [R,L]


works well! "not fair"? Fair to whom? Sure, if I were running a large site selling widgets I would worry about alienation. But as I said I'm not. I'm tired of fielding questions from people who have been previously directed to use firefox but continue using IE. This solves that problem nicely. :D Sure, in "fair"ness they can continue using IE but will be unable to use any LAN or internet tools.



8-)
UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050417 Firefox/1.0.3 (pigfoot)
GetFirefox
sargon
new member
new member
 
Posts: 3
Joined: Wed 02 Mar, 2005 11:58 pm


Return to Web Design and Page Coding

Who is online

Registered users: Google [Bot], Yahoo [Bot]