Best ways to refer visitor to mobile site

RJM62

Touchdown! Greaser!
Joined
Jun 15, 2007
Messages
13,157
Location
Upstate New York
Display Name

Display name:
Geek on the Hill
So I'm doing some work on mobile sites, and I'd like some dependable way to refer mobile visitors to the mobile sites.

I've tried browser detection, which is undependable. Apparently a lot of people spoof their device browsers.

I'm considering trying to sniff the screen resolution and refer, say, anyone whose resolution is, say, 400 or less to the mobile versions. But JavaScript isn't very dependable on mobile devices. Summertime it work, and summertime it don't.

Any other suggestions?

Thanks,

Rich
 
My suggestion is rely on the browser agent string; like you said, some will spoof their browser string. If they are, it's because they WANT to see the non-mobile version of the site on their mobile device. Don't fight them on that. ;-)
 
Ah, okay. The .htaccess version doesn't seem to work... I'll try changing the target like you suggested.

Rich
 
Okay, that works from the main site to the mobile... but it takes away the ability to view the main site if they do want to.

Still, it's a starting point. I guess I can place a cookie or something to allow them to override it.

Thanks again,

Rich
 
How about just telling them there's a mobile version, add a link, and let the user decide if they want to download it.

that's what FlightAware and many other site do, including weatherunderground
 
The link's already there, Murphey. The client wants the auto-redirect, and I have no issue with it as long as it works; but I would like a way for the user to override it.

I may have found that way, actually. The site actually resides on two domains. The old one, on .net, the client allowed to expire some time ago, so I got him the .us until I could get the .net back. Now .net redirects to .us, so he doesn't have to change old stationery and such that already has the .net.

I may be able to do something so that the .net doesn't redirect to .mobi, but the .us does.

-Rich
 
Or else...

Just copy and paste the entire full site to a subdirectory on the mobile site, fix the links, and run a version of the full site on the mobile site for those who enjoy scrolling and zooming...

That's probably the most foolproof way, albeit a kludge of epic proportions.

Rich
 
Just don't commit the #1 faux pas of mobile sites: When a user visits a page and you redirect them to a mobile version, it MUST be a mobile version of THAT PAGE, not just http://mobile.domain.com/

Also, allow them the option to move back and forth - Usually there are Standard and Mobile links on the bottom of the page. Again, bring them back to the SAME page, NOT the main page.

Ugh. HATE redirects that don't bother grabbing the local portion of the URL. Can you tell?
 
The link's already there, Murphey. The client wants the auto-redirect, and I have no issue with it as long as it works; but I would like a way for the user to override it.

I may have found that way, actually. The site actually resides on two domains. The old one, on .net, the client allowed to expire some time ago, so I got him the .us until I could get the .net back. Now .net redirects to .us, so he doesn't have to change old stationery and such that already has the .net.

I may be able to do something so that the .net doesn't redirect to .mobi, but the .us does.

-Rich

On the link from the Mobile site to the Full site, pass a URL parameter, like http://www.deliking.us?m=full

On your site, if the "m" parameter is passed, skip mobile redirect, give them the full site.
 
On the link from the Mobile site to the Full site, pass a URL parameter, like http://www.deliking.us?m=full

On your site, if the "m" parameter is passed, skip mobile redirect, give them the full site.

Not sure how to do that when the redirect is in the .htaccess file, but I'm pretty sure it's doable. Gives me something to do tomorrow. Thanks!

-Rich
 
Not sure how to do that when the redirect is in the .htaccess file, but I'm pretty sure it's doable. Gives me something to do tomorrow. Thanks!

-Rich
You could do it pretty easily with a Rewrite Condition (RewriteCond). You can access the parameter using the QUERY_STRING environment variable.
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#EnvVar . A RewriteCond applies to the RewriteRule immediately following it.

Or you could not do it in the .htaccess and just do it in PHP. It's pretty easy to grab the data you need out of the PHP super global array $_SERVER[]
http://php.net/manual/en/reserved.variables.server.php

You could also do it with a cookie - that way something wouldn't be required in the URL. Lots of ways.

If you give up on the rewrite (they can be a PITA) show me what you have and I should be able to make it work.
 
Last edited:
You could do it pretty easily with a Rewrite Condition (RewriteCond). You can access the parameter using the QUERY_STRING environment variable.
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#EnvVar . A RewriteCond applies to the RewriteRule immediately following it.

Or you could not do it in the .htaccess and just do it in PHP. It's pretty easy to grab the data you need out of the PHP super global array $_SERVER[]
http://php.net/manual/en/reserved.variables.server.php

You could also do it with a cookie - that way something wouldn't be required in the URL. Lots of ways.

If you give up on the rewrite (they can be a PITA) show me what you have and I should be able to make it work.

Thanks Jesse. I'll let you know.

-Rich
 
What's a mobile site?

A version of a site specifically designed to render properly and load quickly on a cell phone, BlackBerry, iPhone, Android, or other Web-enable mobile device. Here are few I've done recently. They'll look pretty ridiculous on a PC, by the way, because they're formatted for handheld devices:
These sites are easy in the respect that the layouts and coding are very simple. But part of the reason they're simple is that there's not a whole lot of consistency between different how different manufacturers' phones and browsers handle anything beyond basic HTML / XHTML.

And just to make things more interesting, a lot of users appear to either spoof other browsers, or are tethering their computers to their phones.

What I'm trying to do is dependably redirect visits that appear to be from a mobile device to the mobile versions of the sites. My preference would be to do it by viewport or screen resolution, so if the device has a horizontal resolution of, say, 640px or less, they would be redirected to the mobile site.

But I haven't come across a dependable way to grab the resolution for the zillions of mobile browsers out there.

I think these mobile sites are rapidly becoming a big deal. A lot of people use their handheld devices preferentially to browse the Web. So as with most other things I've learned in my life, I started selling them to force myself to learn as much about them as I could, as quickly as I could. Sell the job on Monday, learn how to do it on Tuesday, and build it on Wednesday. That sort of thing.

-Rich
 
Interesting. Thanks for the explanation.
 
Back
Top