IIRF - Unable to exclude iPad user agent from redirection rules

Topics: Developer Forum
Aug 26, 2010 at 4:44 PM
I am trying to exclude iPads from a redirection but can't seem to figure out how to get it to work. Here is a sample of a rule: ---------------- RewriteCond %{HTTP_USER_AGENT} (/MIDP2|176x220|220x176|240x320|240x400|320x240|320x320|320x448|448x320|400x240|Android|BlackBerry|Gecko.*Fennec|Gecko.*Minimo|HTC-Touch|HTC_Touch_Pro|iPhone|iPod|Mobile|motorazr|motorola|NetFront|PalmOS|PalmSource|PPC;|samsung|Smartphone|SonyEricsson|VX10000|LG-|LGE-|MOT-|Profile/MIDP-|SCH-|SEC-|SGH-|SIE-|\x20LGE\x20|HP\x20iPAQ\x20h6300|HP\x20iPAQ\x20h6340|HP\x20iPAQ\x20h6365|HTC\x20Touch|Opera\x20Mini) RewriteCond %{HTTP_USER_AGENT} ^(?!iPad.) [I] RewriteCond %{SERVER_NAME} ^(www\.|\.)*(domain)\.com(.*)$ [I] RedirectRule ^/(.*)$ http://www.domain.mobi/$1 [I,R=301] ---------------- The problem I am having is that no matter what I seem to try (and I have tried about 50 different ways to write these rules) the iPad still gets redirected. I only want mobile devices to get redirected. In some cases, if the iPad is *not* redirected, then neither are all the mobile devices! For example, if I put this line first, then nothing is redirected: #RewriteCond %{HTTP_USER_AGENT} !^iPad? [I] I am at my wits end here, and would sincerely appreciate any assistance in figuring out what I am doing wrong. I have tried other expressions, such as: RewriteCond %{HTTP_USER_AGENT} !^iPad? [I] RewriteCond %{HTTP_USER_AGENT} (!^iPad?) [I] and so forth. Thanks!
Aug 26, 2010 at 4:48 PM
Uh that looks really bad. let's try some HTML formatting?

I am trying to exclude iPads from a redirection but can't seem to figure out how to get it to work.

Here is a sample of a rule:

----------------

RewriteCond %{HTTP_USER_AGENT} (/MIDP2|176x220|220x176|240x320|240x400|320x240|320x320|320x448|448x320|400x240|Android|BlackBerry|Gecko.*Fennec|Gecko.*Minimo|HTC-Touch|HTC_Touch_Pro|iPhone|iPod|Mobile|motorazr|motorola|NetFront|PalmOS|PalmSource|PPC;|samsung|Smartphone|SonyEricsson|VX10000|LG-|LGE-|MOT-|Profile/MIDP-|SCH-|SEC-|SGH-|SIE-|\x20LGE\x20|HP\x20iPAQ\x20h6300|HP\x20iPAQ\x20h6340|HP\x20iPAQ\x20h6365|HTC\x20Touch|Opera\x20Mini)

RewriteCond %{HTTP_USER_AGENT} ^(?!iPad.) [I]

RewriteCond %{SERVER_NAME} ^(www\.|\.)*(domain)\.com(.*)$ [I]

RedirectRule ^/(.*)$ http://www.domain.mobi/$1 [I,R=301]
----------------

The problem I am having is that no matter what I seem to try (and I have tried about 50 different ways to write these rules) the iPad still gets redirected. I only want mobile devices to get redirected. In some cases, if the iPad is *not* redirected, then neither are all the mobile devices!

For example, if I put this line first, then nothing is redirected:

RewriteCond %{HTTP_USER_AGENT} !^iPad? [I]

I am at my wits end here, and would sincerely appreciate any assistance in figuring out what I am doing wrong. I have tried other expressions, such as:

RewriteCond %{HTTP_USER_AGENT} !^iPad? [I]
RewriteCond %{HTTP_USER_AGENT} (!^iPad?) [I]

and so forth.

Thanks!
Coordinator
Aug 30, 2010 at 11:37 PM
Edited Aug 30, 2010 at 11:41 PM
Parens in regular expressions are meaningless, unless you are doing captures. I don't know what the user agent string is for the ipad, and you didn't specify it. I'd say, what you want to do makes perfect sense. All you need to do is find a pattern that uniquely matches the ipad user agent. I also suggest that you simplify the rules and condition, during development. Omit everything that is not related to the ipad ua string detection, until you figure it out. Then add in the other stuff you need.