views:

1429

answers:

7
+4  Q: 

Mobile Redirect

I have a webpage and I was recently asked to create the mobile version for it, now that I've done it I was asked to make an automatic redirection so that if the user goes into the webpage through a PDA/iPhone/Smartphone/etc he/she gets automatically directed to the m.website.com but I have no idea how to do this =/ I've tried some php's and javascripts I found using google but nothing so far has helped me. Could you guys?

+4  A: 

Check out WURFL and build a 302 redirector for User-Agents that match its list of mobile browser user-agent strings.

Or, just look for iPhone in the User-Agent and redirect those to your iPhone site. The other browsers command such small market-share it is hardly worth targeting them. iPhone is 67 percent of the mobile web HTML traffic. You could do this in Javascript on your web page.

Genericrich
Make that MobileSafari, so that iPod touch-ers don't feel left out.
Ben Alpert
On the other hand, the iPhone has a good web browser and a decent screen, so can often handle ‘normal’ web pages fine. Other mobile browsers, in particular the abomination that is IE Mobile, may have more need of a site customised to their needs.
bobince
Good point bobince. For our site, we chose to explicitly EXCLUDE the iPhone from the list of mobile devices that will be redirected to a mobile version.
Outlaw Programmer
I don't like to give negatives, but "The other browsers command such small market-share it is hardly worth targeting them." is such an awful attitude that I had to say something. Just because iPhone commands a massive market share it is foolish to treat it at as the only viable platform worth developing for. Phones come and go and your mobile website should not be shackled to one device.
Nathan Taylor
I would send iPhones to the mobile site too, and provide a link to the main site if they want it. A mobile site should be designed for a small screen, and optimized for slow connection. iPhones will like that too.
Lance Fisher
+1  A: 

perhaps if you list your code that is not working, more help could be provided.

if you've got php, User Agent detection works well in most circumstances.

< ?php
$browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
if ($browser == true) { header(”Location: http://www.example.com/“); }
}
?>

Also, this looks like a dupe of: http://stackoverflow.com/questions/291609/identifying-different-mobile-handsets-and-redirecting-to-different-websites

popcnt
Make that MobileSafari, so that iPod touch-ers don't feel left out.
Ben Alpert
A: 

What if I needed the same script for Windows Smart Phones and Blackberrys? Can I just replace iPhone with 'windows ce' and 'blackberry'? Please reply, thanks for your help in advanced.

A: 

A very similar question was asked and answered here:

http://stackoverflow.com/questions/386046/how-do-i-determine-whether-its-a-mobile-device-with-php

Traditionally mobile devices have been detected by comparing the HTTP User-Agent header against a list of well known mobile UA strings. A novel approach instead tries to detect the presence of a desktop OS - anything which is found to not be a desktop OS must then be mobile.

This results in far less false positives.

I've written a post with sample code in Python here:

http://notnotmobile.appspot.com

Detect whether a device is a desktop - if it is not then redirect to your mobile site!

Cheers,

John

jb
A: 

Once you get your mobile subdomain set-up, be sure to refer to this article from A List Apart which describes how mobile devices react to the CSS attribute, media="handheld". Unfortunately, not all react equally.

http://www.alistapart.com/articles/returnofthemobilestylesheet

Anjisan
+2  A: 

I have published the last version of "Apache Mobile Filter", this open source project has in the first 8 months, more than 1100 downloads from sourceforge and I suppose the same from CPAN.

The Apache Mobile Filter allows you to access WURFL from any programming language, not just Java and php that is traditionally used for dynamic mobile web sites.

The module detects the mobile device and passes the WURFL capabilities on to the other web application as environment variables. It can also be used to resize images on the fly to adapt to the screen size of the mobile device. Try it and let me know your opinion.

For more info: http://www.idelfuschini.it/it/apache-mobile-filter-v2x.html

A: 

The "Apache Mobile Filter" is one of the modules of "Apache Module Registry" portal (http://modules.apache.org/search.php?id=1787)