16

What Exception strings are "state of the art" for redirecting iPhone, iPad, Android, tablet, etc. users to a different design?

That is, I realize in the

System -> Configuration -> Design

user interface, there's a feature that allows me to create a regular expression that's matched against the user agent string. What I'm looking for is what specific strings people are using to redirect non-desktop computers to a different mobile and/or response theme?

Or is there a better approach than the "Exception" approach to take these days?

5 Answers 5

15

There are two different versions which we have used. The first is the same one which @Marius made mention of minus the specific "Fennec" mention (which is no longer in the UA string of FF Mobile). I got it from similar sources:

iPhone|iPod|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera Mini

The second is the same, but with the term "Mobile" removed so that the mobile version of a site is not served to the iPad, which includes Mobile in it's user agent. Apple even makes a point to call this out in TN2262:

Safari on iPad is capable of delivering a "desktop" web experience, and users will expect this experience since iPad has a large screen and fast network connectivity. If you have a version of your website that is optimized for mobile devices with small screens, do NOT serve this mobile version to iPad users.

...

Note that the Safari on iPad user agent string contains the word "Mobile", but does not contain the word "iPhone". If you are currently serving mobile content to any browser that self-identifies as "Mobile", you should modify your user agent string checks to look for iPad and avoid sending it the wrong version of your site.

Based on what I see on the FF Mobile, using "Android" in this string will cause trouble if you want the desktop theme served to all tablets (and not just iPads) since it's been decided to include it in the UA string for various reasons.

I've honestly not personally tested the coverage of the above strings. I do know this: It's a complicated mess! :)

Note: If you are setting this up on EE 1.12 or earlier (haven't checked 1.13) you will need a patch from Magento Support for the FPC to work properly. It fails to take design exceptions into account in the release build.

Update 1:

The noted bug requiring a patch for design exceptions to work still exists in EE 1.13.0.0 and 1.13.1.0. There is a patch available from Magento support and it's on their known issues list: SUPEE-1598

5
  • I'd check 1.13 for you... but...
    – philwinkle
    Jul 16, 2013 at 4:00
  • 1
    I could check easily enough, I'm just too lazy at the moment. :)
    – davidalger
    Jul 16, 2013 at 4:04
  • In all seriousness, this is a pretty complete list. +1.
    – philwinkle
    Jul 16, 2013 at 4:06
  • @davidalger, I have used the first expression (you mentioned). Now how to display desktop site in all tablets, ipad, ipad mini ? because they all are showing mobile themes. Mar 5, 2016 at 5:23
  • where do I put these strings in to redirect mobile devices to www.m.myDOMAIN.com for mobile devices? Magento 1.9.1
    – Allysin
    Dec 10, 2016 at 21:53
7

I have added 2 design exceptions, one for tablets, for which I serve my desktop theme and one for phones, for which I serve my mobile theme. I add the exception targeting the tablets first, and then the exception targeting the mobile phones

Tablets

iPad|Silk|Kindle|Xoom|SCH-I800|Tablet|GT-P10|SC-01C|SHW-M180S|SGH-T849|SCH-I800|SHW-M180L|SPH-P100|SGH-I987|zt180|HTC(.Flyer|\\_Flyer)|Sprint.ATP51|ViewPad7|pandigital(sprnova|nova)|Ideos.S7|Dell.Streak.7|Advent.Vega|A101IT|A70BHT|MID7015|Next2|nook|Windows NT|DROID RAZR

Phones

android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|iP(hone|od)|iris|kindle|lge |maemo|meego.+mobile|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|(Android.+Mobile)|NOKIA|SymbianOS|N900|BlackBerry|Mobile

This works pretty much 100% as expected I must give credit, and a huge thanks to beeplogic who's regex I used as my foundation, Thank you beep!

1
  • 1
    I know this is old but just wanted to notice that Ipad also uses the Mobile string so you should remove it from the phones list Apr 1, 2015 at 7:06
2

Here is a list of possible values. I'm almost sure that these are not all the possible values, but it covers most cases:

iPhone|iPod|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera Mini|Fennec

Sources:
http://magebase.com/magento-tutorials/magento-design-exceptions-explained/
http://inchoo.net/ecommerce/magento/magento-mobile-theme-imobile/

1

This is one I've used:

android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|meego.+mobile|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino
0

I had a specific need to filter out specific versions of Android devices. Similar approach can be used to filter out iOS versions.

The following example matches iPad, iPhone and all Android except the versions "2.*", "3.*", "4.0*"

iPad|iPhone|Android ((?!(2\.|3\.|4\.0)).)

It is using negative lookarounds, see the explanation here.
Note that trying to mimic "> 2.3" will not work in regex, but need a workaround as the example.
A great resource to test regex matching on strings online is Rubular

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.