1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Re-direct iphone/pad/pod using .htaccess

Discussion in 'Web Design & Development' started by ZeusTheDog, Jan 26, 2013.

Thread Status:
Not open for further replies.
  1. ZeusTheDog

    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.
     
  2. JiminSA

    JiminSA

    Joined:
    Dec 15, 2011
    Messages:
    3,327
    First Name:
    Jim
    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:)
     
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 733,556 other people just like you!

Loading...
Similar Threads - direct iphone using
  1. Berrymanrgb
    Replies:
    0
    Views:
    255
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1087009

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice