The only way I could find to do this was a hack in which I:
Used css media queries to detect phones using max-device-width
Set a change in style on this basis - I changed body color from #000000 to #000001
Use an OnLoad to call a Javascript to check the body color.
Redirect on this basis. (In my own case I actually used a window.confirm call to offer the user a choice, rather than forcing redirection).
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Phone test</title>
<meta name="viewport" content="width=device-width">
<style type="text/css">
body
{ color: rgb(0, 0, 0);}
@media screen and (max-device-width:600px), screen and (max-width:600px)
{
body{ color: rgb(0, 0, 1);}
}
</style>
<script type="text/javascript">
<!--
function doPhoneCheck()
{
var col;
if(document.body.currentStyle)
{
col = document.body.currentStyle.color; // IE
}
else
{
col = getComputedStyle(document.body).getPropertyValue("color");
}
if(col =="rgb(0, 0, 1)")
{
window.location.href="http://www.apple.com/";
}
}
//-->
</script>
It detects all iPhones to 6+, and the Android and Windows phones I've tested. It discriminates against all current iPads and against the laptops and desktops I've tried.
NB
(1) For color you must use rgb and leave spaces exactly as written.
(2) I found similar code would not detect body background-color for some unknown reason.
(3) The key to detecting the css style is to use getComputedStyle() (or currentStyle for IE) rather than getStyle().
(4) Even though the change in body color is imperceptible, it can be over-ridden by specifying colors for all your css classes etc.