Does anyone know how i would go about using .htaccess to redirect users of a specific browser from hitting my sites, for example, lets say a surfer is using Opera, how would i go about redirecting that surfer to a different website?
Regards,
Lee
Does anyone know how i would go about using .htaccess to redirect users of a specific browser from hitting my sites, for example, lets say a surfer is using Opera, how would i go about redirecting that surfer to a different website?
Regards,
Lee
You can use Rewrite in .htaccess to do that. Test for the particular browser (user-agent as it is called in htaccess language) and then send the surfer somewhere else. It would go something like this (showing 2 test conditions, just add [OR] to each line except the final test if you want to include a bunch of browsers):
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Opera [OR]
RewriteCond %{HTTP_USER_AGENT} ^SomeOtherBrowser
RewriteRule ^(.*)$ http://www.someothersite.com/
However, it's more common to let the user enter and then test in PHP/HTML/CSS to see which browser it is and selectively use bits of code to ensure the page displays well with that particular browser. It's normally much easier to include a bit of extra conditional code in a single page than to maintain duplicate pages/sites for various browsers.
Kevin
Ah very cool, thanks Kevin
I know i had a code to do this a few years back but i cant find it anywhere right now, this is gonna be a great help, thanks
Regards,
Lee
I didn't know about this. Interesting. Do many webmasters commonly use something like this? Or do most people design their sites as best they can, checking it in a couple of browsers and hoping it goes OK for the others?
First, you're welcome, Lee...and please don't neglect users of my beloved Opera, I think it's the best browser currently available!
As for designing for multiple browsers, I would say the majority of sites are created so they look good in IE and the rest of the browsers are largely ignored. I loathe IE but still use it at times because there are sites where other browsers simply won't work...a button refuses to click and do something or a content panel remains blank, etc. It's because IE dominated the browser world for such a long time that many people think it sets the standard. In reality, IE is the least compliant with W3C standards (the international consortium that decides how HTML code should work). Being an 800 pound gorilla, Microsoft simply ignores the rules and thus code that works well in all other browsers does not work in IE.
A good designer will test the pages in the most popular browsers and try to tweak it by including conditional bits of code that execute only on browsers which need it to display the page correctly. There are sites which can take a URL as input and then display an image of how the page will look in almost any browser so it's not necessary to have a PC and Mac, for example. Check out http://browsershots.org/
Kevin
Well Opera was just the example i was using, its actually a little more technical than that but i know what to search for user-agent wise now hehe
Most of our normal sites are actually designed to work with multiple browsers but this project is a little different than normal
Regards,
Lee
Bookmarks