• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Redirect Mobile Browsers
PostPosted: Sat Feb 13, 2010 6:34 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Fri Feb 02, 2007 4:31 pm
Posts: 2385
Location: Comox Valley, BC
With the increasing use of handheld devices to surf the net, more and more of the sites I do want to offer completely different content/styles to mobile users.

One way to accomplish this is to have a separate subdomain for mobiles and redirect them via the .htaccess file:

\$1:
RewriteEngine on
RewriteBase /

# prevent looping
RewriteCond %{HTTP_HOST} !^mobile.yoursite.com$

# if the browser accepts these mime-types, it's definitely mobile, or pretending to be
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]

# a bunch of user agent tests
RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android"[NC]

# put your rewrite rules here
RewriteRule ^(.*)$ http://mobile.yoursite.com/  [L,R=302]


Note: This example assumes a subdomain of "mobile".

To see what your site looks like on a mobile phone, you can use these emulators:

http://emulator.mtld.mobi/emulator.php
http://www.testiphone.com/

Nullig


Last edited by Nullig on Sun Feb 14, 2010 1:42 am, edited 1 time in total.

Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Redirect Mobile Browsers
PostPosted: Fri Feb 18, 2011 11:21 am 
Offline
Power Poster
Power Poster

Joined: Fri Mar 03, 2006 1:32 pm
Posts: 610
Nullig \Nullig:
With the increasing use of handheld devices to surf the net, more and more of the sites I do want to offer completely different content/styles to mobile users.

One way to accomplish this is to have a separate subdomain for mobiles and redirect them via the .htaccess file:



But in that case you need to maintain TWO completely different sites, which adds a lot of work, especially with large sites. Wouldn't it be simpler to incorporate the browser sniffing into the template and just call a different CSS? Or would it even be possible to switch templates?

E.g. for WORDPRESS there exists a plugin which just sends a completely different theme to mobile devices, and it works great.

Cheers,
Alex


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Redirect Mobile Browsers
PostPosted: Fri Feb 18, 2011 6:37 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Fri Feb 02, 2007 4:31 pm
Posts: 2385
Location: Comox Valley, BC
Yes, it does require maintaining 2 sites, but in some cases you want to show different content - more concise content.

The maintenance is minimal, as the template and stylesheets are bare bones.

Nullig


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Redirect Mobile Browsers
PostPosted: Thu Mar 31, 2011 8:59 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Wed Mar 21, 2007 11:01 am
Posts: 168
Location: Grand Rapids, MI
Great thread. Great script. I got this working today, but have one minor issue.

If I'm an iPhone user or other with full browser capability, I'd like to show the mobile version first, but have the option for the user to click "view the full site" and have it show.

It's setup like this:
"http://www.domain.com" for main site
"http://www.domain.com/mobile" for mobile site

Redirect sends mobile user to /mobile directory and it works great. But, clicking to view full site just loops them back to the mobile directory.

Any tricks to making this work? Thanks!


Last edited by Dr.CSS on Thu Jan 26, 2012 6:33 pm, edited 1 time in total.
Please use double quotes on fake links so they aren't clickable...


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Redirect Mobile Browsers
PostPosted: Fri Apr 01, 2011 7:28 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Sun Jul 27, 2008 1:36 am
Posts: 218
Location: USA
jtcreate \jtcreate:
...
Redirect sends mobile user to /mobile directory and it works great. But, clicking to view full site just loops them back to the mobile directory.

Any tricks to making this work? Thanks!

Hi,

How about setting a cookie when a user opts for the full site and then check for the cookie in the .htaccess file, with another RewriteCond? E.g.:
\$1:
...
# prevent looping
RewriteCond %{HTTP_COOKIE} !_full_site_please_blah_blah_blah
...

_________________
Nearly all men can stand adversity, but if you want to test a man's character, give him power.
- Abraham Lincoln


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Redirect Mobile Browsers
PostPosted: Wed Apr 06, 2011 6:15 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Mon Sep 22, 2008 7:44 am
Posts: 77
Hi there

I came up with a new solution for this. I also wanted to send mobile users off to separate 'mobile template' pages and iphone users to the main site.

BUT I wanted my visitors to be able to switch between the two.

The solution that works for me is to place a php script into a default.php file as so:

This is an adaptation from:

Mobile version detection
-----------------------------------------------------
compliments of http://www.buchfelder.biz/



\$1:
 
<?php

if($mobile){
   header('Location: http://www.mydomain.com.au/mobile.htm');
   } else {
   header('Location: http://www.mydomain.com.au/index.php');
   }

$text = $_SERVER['HTTP_USER_AGENT'];
$var[0] = 'Mozilla/4.';
$var[1] = 'Mozilla/3.0';
$var[2] = 'AvantGo';
$var[3] = 'ProxiNet';
$var[4] = 'Danger hiptop 1.0';
$var[5] = 'DoCoMo/';
$var[6] = 'Google CHTML Proxy/';
$var[7] = 'UP.Browser/';
$var[8] = 'SEMC-Browser/';
$var[9] = 'J-PHONE/';
$var[10] = 'PDXGW/';
$var[11] = 'ASTEL/';
$var[12] = 'Mozilla/1.22';
$var[13] = 'Handspring';
$var[14] = 'Windows CE';
$var[15] = 'PPC';
$var[16] = 'Mozilla/2.0';
$var[17] = 'Blazer/';
$var[18] = 'Palm';
$var[19] = 'WebPro/';
$var[20] = 'EPOC32-WTL/';
$var[21] = 'Tungsten';
$var[22] = 'Netfront/';
$var[23] = 'Mobile Content Viewer/';
$var[24] = 'PDA';
$var[25] = 'MMP/2.0';
$var[26] = 'Embedix/';
$var[27] = 'Qtopia/';
$var[28] = 'Xiino/';
$var[29] = 'BlackBerry';
$var[30] = 'Gecko/20031007';
$var[31] = 'MOT-';
$var[32] = 'UP.Link/';
$var[33] = 'Smartphone';
$var[34] = 'portalmmm/';
$var[35] = 'Nokia';
$var[36] = 'Symbian';
$var[37] = 'AppleWebKit/413';
$var[38] = 'UPG1 UP/';
$var[39] = 'RegKing';
$var[40] = 'STNC-WTL/';
$var[41] = 'J2ME';
$var[42] = 'Opera Mini/';
$var[43] = 'SEC-';
$var[44] = 'ReqwirelessWeb/';
$var[45] = 'AU-MIC/';
$var[46] = 'Sharp';
$var[47] = 'SIE-';
$var[48] = 'SonyEricsson';
$var[49] = 'Elaine/';
$var[50] = 'SAMSUNG-';
$var[51] = 'Panasonic';
$var[52] = 'Siemens';
$var[53] = 'Sony';
$var[54] = 'Verizon';
$var[55] = 'Cingular';
$var[56] = 'Sprint';
$var[57] = 'AT&T;';
$var[58] = 'Nextel';
$var[59] = 'Pocket PC';
$var[60] = 'T-Mobile';   
$var[61] = 'Orange';
$var[62] = 'Casio';
$var[63] = 'HTC';
$var[64] = 'Motorola';
$var[65] = 'Samsung';
$var[66] = 'NEC';

$result = count($var);

for ($i=0;$i<$result;$i++)
{   
    $ausg = stristr($text, $var[$i]);   
    if(strlen($ausg)>0)
    {
        header("location: $mobile");
        exit;
    }
   
}
?>


And then just added this to the .htaccess
\$1:
DirectoryIndex default.php index.php index.htm index.html



My question is though "Will this have a negative effect on the Search Engines?"


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Redirect Mobile Browsers
PostPosted: Tue Jan 24, 2012 10:09 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Sun Feb 28, 2010 10:54 pm
Posts: 363
Hi guys, so here's what I did to redirect mobile users to a different CMSMS template, please let me know if this is a good approach, so far it seems to be working.

I just created a Global Content Block with the following code to redirect users;

\$1:
{literal}
<__script__ type="text/javascript">
if ( (screen.width < 1024) && (screen.height < 768) ) {
window.location = 'http://www.website.com/mobile.htm';
}
</__script>
{/literal}


...and placed this at the top of my home page template:
\$1:
{global_content name='mobilescript'}


Not sure if its the best approach, but seems to be working, please advice. Thx


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Redirect Mobile Browsers
PostPosted: Tue Jan 24, 2012 10:19 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 8170
Location: Fernie British Columbia, Canada
A simple UDT would do it... something like:

\$1:
$browser = cge_utils::get_browser();
if( $browser->isMobile() )
{
   redirect('http://m.website.com');
}

_________________
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Redirect Mobile Browsers
PostPosted: Thu Jan 26, 2012 6:37 pm 
Offline
Administrator
Administrator
User avatar

Joined: Thu Mar 09, 2006 5:32 am
Posts: 12674
Location: Arizona
Why not just use CSS to do this?...

http://multiintech.com/testing.html

it doesn't look so good on the first emulator using the Nokia N70 but the other works ok, of course I'm not done with it...

_________________
Check ver. CMSMS, PHP, server OS, in System Information page.
Default content http://multiintech.com/defaultcontent/
People are Wonderful
Business is Great
Life is Terrific
Ever wonder what happened to the Album module? Well it is alive and well.
http://album.multiintech.com/
$1


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: pwg


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Hosting Nation - Managed CMSMS Hosting