Mobile app version of vmapp.org
Login or Join
Steve110

: Desktop ↔ mobile site redirection logic I want the to know the correct desktop to mobile redirection logic. How should a visitor be sent to mobile version or the desktop version of site?

@Steve110

Posted in: #Desktop #GooglebotMobile #Mobile

I want the to know the correct desktop to mobile redirection logic. How should a visitor be sent to mobile version or the desktop version of site?

I've a mobile site: m.example.com and desktop site at: example.com What I'm using now:


First visits will be detected and redirected to mobile or desktop version
Second time onward same session visit to any URL (mobile or desktop) will not be redirected. I mean if first time a m.example.com is served and then the user types example.com then desktop version will be served from his mobile device


What is the correct way when to transfer a visitor to mobile or the desktop version?

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Steve110

3 Comments

Sorted by latest first Latest Oldest Best

 

@Angela700

I actually did this too. You can use modrewrite rules to check the user agent of the incoming device to see if its a mobile device. I use the data from the scripts at:
detectmobilebrowsers.com/

When the detection takes place, a cookie must be set for a long lifetime (in your case, use 10 years). Its the cookie that you use that will prevent the detection from happening again.

Here's code you can use in your document root's .htaccess file to help you get started. Just replace anything in triangle brackets with correct values as it applies to your site, and feel free to remove NC if you want case sensitivity turned on.

RewriteCond %{HTTP_COOKIE} !DETECTED=1;?
RewriteCond %{HTTP_USER_AGENT} ^<insert mobile UA's here>$ [NC]
RewriteCond %{HTTP_HOST} ^(www.|)<insert main domain here>$ [NC]
RewriteRule ^<desktop links to redirect>$ <insert mobile domain here>/ [NC,R=301,L,CO=DETECTED:1:.<insert main domain here>:<# seconds to keep redirection remembered>:/]

10% popularity Vote Up Vote Down


 

@Chiappetta492

There's a script called MobileDetect, if checks if the visitor is a user via the browser headers. Requires updating from time to time, but other than that is works very easy:

$detect = new Mobile_Detect();
define(IS_MOBILE_USER, $detect->isMobile() && !$detect->isTablet() );

if( $onDesktopSite && IS_MOBILE_USER && !isset($_SESSION['ignore_mobileView']) ){
// Request_uri to keep the user on the actual page, no redirect to home needed
header('Location: m.example.com/'.$_SERVER['REQUEST_URI']); }


On that site you can add a "view as desktop", which sets $_SESSION['ignore_mobileView'] so the user can remain on the big site (don't forget the possibility to switch back).

As long as there's a session, the site will remember if the user wants the desktop-/mobile version.
You could switch to cookies if you want it stored for a longer period of time.

10% popularity Vote Up Vote Down


 

@Shanna517

You can use Google's recommendations for mobile sites.
Your first step is in compliance with those recommendations but not the second step. You should always redirect based on user agent detection and not session - but allow users the option to choose (usually as part of the footer).

You also need to implement canonical tags (on the mobile pages) and alternate tags (on the desktop pages).

Google's recommendations in details:
developers.google.com/webmasters/smartphone-sites/redirects https://developers.google.com/webmasters/smartphone-sites/details

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme