创建与部分用户代理匹配的 WURFL 补丁
我正在使用 WURFL 来识别用户是否使用移动设备。某些用户代理字符串被错误地识别为移动设备,从而导致内容类型设置不正确。
下面是现实生活中用户代理的行为示例:
Mozilla/5.0 (GTmetrix http://gtmetrix.com/; X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
内容类型设置为 application/vnd.wap.xhtml+xml
而不是 text/html
。
我想向 web_browsers_patch.xml 文件添加一个条目,以便将其识别为非移动浏览器。
以下工作:
<device id="mozilla_ver5"
user_agent="Mozilla/5.0 (GTmetrix http://gtmetrix.com/; X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"
fall_back="generic_web_browser" />
但是,为了不必添加所有可能的用户代理变体,我想部分匹配它。类似于:
<device id="mozilla_ver5"
user_agent="Mozilla/5.0 (GTmetrix"
fall_back="generic_web_browser" />
不幸的是,这不起作用 - 页面的内容类型再次设置不正确。
是否可以添加与部分用户代理字符串匹配的 WURFL 补丁?如何?
(相关奖励问题:如何确定用户代理字符串与哪个配置文件匹配?)
I'm using WURFL to identify whether a user is on a mobile device. Some User-Agent strings are incorrectly recognized as mobile devices which in turn causes the content-type to be set incorrectly.
Here an example of a real life user agent behaving like this:
Mozilla/5.0 (GTmetrix http://gtmetrix.com/; X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
The content-type then is set to application/vnd.wap.xhtml+xml
instead of text/html
.
I would like to add an entry to the web_browsers_patch.xml file in order to recognize it as a non mobile browser.
The following works:
<device id="mozilla_ver5"
user_agent="Mozilla/5.0 (GTmetrix http://gtmetrix.com/; X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"
fall_back="generic_web_browser" />
However, in order to no have to add all possible user agent variations, I would like to match it partially. Something like:
<device id="mozilla_ver5"
user_agent="Mozilla/5.0 (GTmetrix"
fall_back="generic_web_browser" />
Unfortunately, this does not work - the content type of the page is again set incorrectly.
Is it possible to add a WURFL patch matching partial user agent strings? How?
(Related bonus question: How can I determine to which profile a user agent string was matched?)
I'm using the 51Degrees Foundation API available on http://51degrees.codeplex.com/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 51Degrees,您可以拆开它返回的一些对象。看一下这里:http://51 Degrees.mobi/Support/Documentation/Foundation/WURFLMappingTable。 aspx
这应该会为您提供 user_agent 和一系列其他属性来满足您的需求。
If you are using 51Degrees, you can take apart some of the objects it returns. Take a look here : http://51degrees.mobi/Support/Documentation/Foundation/WURFLMappingTable.aspx
This should get you the user_agent and a bevy of other properties to suit your needs.