April 12th, 2013, 11:44 PM
Redirect from specific page to mobile page
My client has created a QR Code that goes to a specific page on a non-mobile site. The client does have a mobile site, m.customersdomain.com
Question is, the QR Code has already been submitted to print for advertising and is going to a regular URL.
Is there a way to look for mobile devices that hit this one non-mobile page and redirect them to a specific mobile URL / page?
April 13th, 2013, 05:28 AM
That's easily possible.
Get a list of all common mobile browser user-agents.
Store them somewhere. In a DB, JSON file, or just as an array..
Check each visitor's user-agent to see if it exists in your list of mobile user-agents. If it does, do the redirect.
Check the screen resolution. If it's lower than the standard (lowest) desktop/laptop screen size, or if it's mobile size, do the redirect (in JS).
April 13th, 2013, 12:32 PM
Have this so far for JS:
if ((screen.width <= 700) &&
window.location = "http://m.customersite.com/gotopage";
I just need to figure out how to look @ the current URL, and if it is in fact http://customersite.com/gotopage, then send them via window.location to http://m.customersite.com/gotopage
April 13th, 2013, 12:49 PM
This may do it:
if ((screen.width <= 700) &&
window.location = "mobileurl";
Any better way?
April 13th, 2013, 12:53 PM
You shouldn't need to check the current URL unless you've got that code running on both sites. If so, that's a problem. Only have that code on the non-mobile site. That way, you won't need to check the current URL.
April 13th, 2013, 12:55 PM
Correct...this would only be on the regular site...not going to do on mobile site.
April 13th, 2013, 12:57 PM
So you wont need to check the current URL, then xD
April 13th, 2013, 12:59 PM
April 13th, 2013, 01:00 PM
Current regular site has 5 pages lets say.
I would redirect the user away from regular page4 b/c of what this particular QR Code URL is...and send them to the mobile version of page4.
If this is a mobile device and they're trying to hit page 4, the redirect them to the mobile site version of page 4.
April 13th, 2013, 01:11 PM
Ah, right, it's best if you do that through server-side, then:
Make sure you change the $pages array to contain the relevant elements and keys.
$mobilePlatforms = array
$pages = array
'www.blahblah.com/page1' => 'www.m.blahblah.com/page1.php',
'www.blahblah.com/page2' => 'www.m.blahblah.com/page2.php',
'www.blahblah.com/page3' => 'www.m.blahblah.com/page3.php',
'www.blahblah.com/page4' => 'www.m.blahblah.com/page4.php',
'www.blahblah.com/page5' => 'www.m.blahblah.com/page5.php',
$currentPage = $_SERVER['SCRIPT_NAME'];
$userAgent = $_SERVER['HTTP_USER_AGENT'];
foreach( $mobilePlatforms as $platform )
if ( stripos( $userAgent , $platform ) !== false )
//by default, we'll send them to the mobile homepage
$location = 'www.m.blahblah.com';
//but we then check if they're on a page that we want a custom redirect for
if ( empty( $pages[ $currentPage ] ) === false )
$location = $pages[ $currentPage ];
header( 'Location: ' . $location );
Last edited by navnav; April 13th, 2013 at 01:14 PM.
April 13th, 2013, 01:46 PM
Thanks tons NavNav...should be able to test this by tonight or tomorrow...will let you know for sure.