Re-direct iphone/pad/pod using .htaccess

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

ZeusTheDog

Thread Starter
Joined
Jan 26, 2013
Messages
1
I've tried so many options over countless days and hours... I'm going blind.

Apache server is version 2.2.17 (Network Solutions)

Am attempting to redirect iPhones/iPad/iPods devices via the .htaccess file.

The current-most attempt reads:

Options +FollowSymlinks

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "iPhone | iPad | iPod | android" [NC]
RewriteCond %{HTTP_HOST} ^((www.)?mysite.com)$
RewriteCond %{HTTP_HOST} ^www.iphone.mysite.com$
RewriteRule ^(/)?$ iOS [L]

# Latest failed attempt of several:
# RewriteCond %{HTTP_USER_AGENT} ^.*iP(hone|od)(;|\s).*$
# RewriteRule ^/?$ http://iphone.mysite.com/$1 [R=302,L]

Previously attempted results were "Safari: too many re-directs..." or, no discrimination/re-direction.

Can anyone assist? Great thanks.
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,400
Hi and welcome to TSG Zeus:)
Personally, I would do my checking internally rather than .htaccess, something like this:-
find out the browser...
PHP:
$ua = get_browser($_SERVER['HTTP_USER_AGENT']);
and then you could either check for the many 'mobile' browsers...
PHP:
<? if (
 stristr($ua, "Windows CE") or
 stristr($ua, "AvantGo") or
 stristr($ua,"Mazingo") or
 stristr($ua, "Mobile") or
 stristr($ua, "T68") or
 stristr($ua,"Syncalot") or
 stristr($ua, "Blazer") ) {
 $DEVICE_TYPE="MOBILE"; // this would detect most of the mobile devices
 } 
 if (isset($DEVICE_TYPE) and $DEVICE_TYPE=="MOBILE") {
 $location='mobile/index.php';
 header ('Location: '.$location);
 exit;
 }
 ?>
or check for static browsers...
PHP:
$bname = "not_found";
 if(preg_match('/MSIE/i',$ua) && !preg_match('/Opera/i',$ua)) 
    { 
        $bname = 'Internet Explorer'; 
        $ub = "MSIE"; 
    } 
    elseif(preg_match('/Firefox/i',$u_agent)) 
    { 
        $bname = 'Mozilla Firefox'; 
        $ub = "Firefox"; 
    } 
    elseif(preg_match('/Chrome/i',$u_agent)) 
    { 
        $bname = 'Google Chrome'; 
        $ub = "Chrome"; 
    } 
    elseif(preg_match('/Safari/i',$u_agent)) 
    { 
        $bname = 'Apple Safari'; 
        $ub = "Safari"; 
    } 
    elseif(preg_match('/Opera/i',$u_agent)) 
    { 
        $bname = 'Opera'; 
        $ub = "Opera"; 
    } 
    elseif(preg_match('/Netscape/i',$u_agent)) 
    { 
        $bname = 'Netscape'; 
        $ub = "Netscape"; 
    }
 }
 if ($bname == "not_found") $DEVICE_TYPE="MOBILE";
 if (isset($DEVICE_TYPE) and $DEVICE_TYPE=="MOBILE") {
 $location='mobile/index.php';
 header ('Location: '.$location); 
 exit;
I HAVEN'T TESTED this code, so don't rely on it - it's just to give you an idea for a different approach:)
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top