User agent for windows phones - htaccess mobile redirect

Hello,

Does anyone know the proper value for windows phones user agent to handle mobile redirect using htaccess?

example, I use this for iphone.

RewriteCond %{HTTP_USER_AGENT} ^.iPhone.$

But it seems/looks that there are many options for Windows phones (iemobile, Windows/Phone, etc.)

Thanks in advance for the help!

Jesus

You can find a massive list here: http://www.useragentstring.com/pages/Mobile%20Browserlist/

But it doesn’t look like there’s much on there for Windows phones.

It looks like this is what the Windows 8 phone user agent will look like: http://blogs.windows.com/windows_phone/b/wpdev/archive/2012/10/17/getting-websites-ready-for-internet-explorer-10-on-windows-phone-8.aspx

However, it’s usually a best to target browser features and screen resolutions, rather than user agents, as there are so many various of user agents. Plus, user agents can be spoofed

You need to remember that Internet Explorer, Firefox, Opera and Safari all allow the useragent to be set to anything at all and so any of those four browsers running on a computer can identify itself as any type of phone. That not only makes it really easy to test any code that you write that makes use of the useragent - and it also shows how pointless such tests are.

Targetting viewport size is generally the best way of determining whether the device is using a mobile phone sized display but you can’t detect that on the server at all.

Thank you Force Flow and felgall for your answers.

I’ll try to take a look at the viewport port option as it makes more sense. I’ll try to post my code here once I figure this out.

Thanks again!

Jesus

Jesus
As Fegall and ForceFlow both recommended that you review Cascading Style Sheets ( CSS) media queries.

I totally agree that focusing on browser capabilities is a vastly superior method of handling these sorts of things in general. That said, I do think that if someone is actively monkeying with browser settings to the point they are simulating being another browser or device then they have crossed the line of voiding the warranty – they are actively lying to you.

I’ll also note viewports can be tricky in this day and age now that we are seeing very high pixel density displays and such, often operated with imprecise fat fingers.

[dupe redacted]

Of course Microsoft are the ones who started using that field to lie when they started claiming that their browser was Mozilla (which was the identifier in the useragent to identify Netscape). No browser since then has ever done anything but lie in that field as they all claim to be Netscape with the Mozilla reference at the start of the field. If ALL browsers actively lie in that field then why shouldn’t someone change the value in the USER agent to identify the browser the way they want - after all that’s what all the browsers do anyway.

Also most browsers give you a choice of which of their competitors useragents you want to use to identify their browser. Safari running on Windows has a setting to identify itself as iPhone and Chrome has a similar setting for identifying itself as Android. Those are settings provided by Apple and Google as a part of the browser setup.

So the liars here are Microsoft, Apple and Google. So they are the people you should be telling to stop monkeying with the settings and let the USER decide how they want to identify THEIR browser - it is after all called a USER agent and so I should be the one choosing the value to use for it in my browsers and not Microsoft, Apple or Google offering values that pretend to be Netscape.

Also if I were to set the useragent in my browsers to “Steve’s Microsoft Browser”, “Steve’s Apple Browser” and “Steve’s Google Browser” then unlike the supplied useragents I am not lying as that would be an accurate description of what they are - it wouldn’t match any of the utterly stupid useragent tests but then the only valid use for testing that field is to gather statistics on how many people use which lying useragent.

I’m not sure your beef with Microsoft makes much sense here – why is it wrong to serve the pages to users in the way they ask for them? Is it my job as a developer to somehow re-divine what browser people are using even if they are telling me they are using a different one intentionally?

Also most browsers give you a choice of which of their competitors useragents you want to use to identify their browser. Safari running on Windows has a setting to identify itself as iPhone and Chrome has a similar setting for identifying itself as Android. Those are settings provided by Apple and Google as a part of the browser setup.

Those options make loads of sense – loads easier to test webapps with desktop browsers. Sometimes you want to fake it. Especially with Safari for windows which is almost purely a tool for developers to test things with safari to make the web better for apple customers on apple devices.

So the liars here are Microsoft, Apple and Google. So they are the people you should be telling to stop monkeying with the settings and let the USER decide how they want to identify THEIR browser - it is after all called a USER agent and so I should be the one choosing the value to use for it in my browsers and not Microsoft, Apple or Google offering values that pretend to be Netscape.

Also if I were to set the useragent in my browsers to “Steve’s Microsoft Browser”, “Steve’s Apple Browser” and “Steve’s Google Browser” then unlike the supplied useragents I am not lying as that would be an accurate description of what they are - it wouldn’t match any of the utterly stupid useragent tests but then the only valid use for testing that field is to gather statistics on how many people use which lying useragent.

Early versions of MSIE did use Mozilla’s user agent string but MSIE has always identified itself as well. See http://www.nczonline.net/blog/2010/01/12/history-of-the-user-agent-string/ for a bit of history here.

Moreover, I think the IETF doesn’t agree with your definition of USER agent. Section 14.43 of the RFC states:

The User-Agent request-header field contains information about the user agent originating the request. This is for statistical purposes, the tracing of protocol violations, and automated recognition of user agents for the sake of tailoring responses to avoid particular user agent limitations. User agents SHOULD include this field with requests. The field can contain multiple product tokens (section 3.8) and comments identifying the agent and any subproducts which form a significant part of the user agent. By convention, the product tokens are listed in order of their significance for identifying the application.

Nowhere do they say it is an end-user adjustable header.