7

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?

Tsundoku
  • 9,104
  • 29
  • 93
  • 127

9 Answers9

3

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
  • 4,611
  • 5
  • 36
  • 55
  • 1
    Make that MobileSafari, so that iPod touch-ers don't feel left out. – Sophie Alpert Mar 04 '09 at 06:43
  • 4
    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 Mar 04 '09 at 12:54
  • 1
    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. – Tim Frey Mar 31 '09 at 16:41
  • 13
    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 Aug 23 '09 at 19:20
  • 1
    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 Oct 27 '09 at 07:28
2

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

2

I wrote a JS script called "redirection_mobile.js" to solve this issue. It detects the User Agent and redirects to a mobile version if you're accessing a site from a mobile device.

In some case you want to redirect from a mobile device to a desktop version (like with a link "Go to the main site"), the script will handle that and once you finish your session, you'll access to the mobile version again.

You can find the source code on github here https://github.com/sebarmeli/JS-Redirection-Mobile-Site and you can read more details in one of my article here:

http://blog.sebarmeli.com/2010/11/02/how-to-redirect-your-site-to-a-mobile-version-through-javascript/

sebarmeli
  • 17,949
  • 7
  • 35
  • 40
1

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: Identifying different mobile handsets and redirecting to different websites

Community
  • 1
  • 1
popcnt
  • 4,519
  • 1
  • 16
  • 14
0

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

0

This bit of Javascript also might assist:

<script>
    if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB10|IEMobile|Opera Mini/i.test(navigator.userAgent) ) //Specify the mobile devices that you would like this if statement to apply to. 
    {
        image_y = document.getElementById('bodyID'); //Get the ID of the body and assign it to a variable.
        image_y.parentNode.removeChild(image_y); //Remove the body to prevent anything loading on the screen in case there are issues with the window location redirect.
        window.location = "mobile.html"; //Re-assign the window location to a new html page that is caters for the redirect. 
    }
</script>

I placed it in the start of the HTML body.

owlwink
  • 91
  • 9
0

I use http://detectmobilebrowser.com, and found it is the quickest and easiest way. It works quite well. This site generates server scripts automatically (php, perl, python, coldfusion, apache, jquery, etc.) that detects mobile browser and redirects accordingly. You can just copy and paste the code somewhere in your Index file.

Chris
  • 636
  • 1
  • 5
  • 6
  • Chris - this is an identical "boilerplate" answer to [this one](http://stackoverflow.com/questions/1865934/redirect-url-to-mobile-version/6275716#6275716). Please ensure your answers are tailored to answer the OP's specific problem. Posting identical answers like this gets flagged by the community as spam. Also if you're in any way associated with this project then you should disclose this. Thanks. – Kev Jun 08 '11 at 08:38
  • hmm... that's an interesting way of seeing it. I just answered two questions that are essentially the same and tried to be helpful to both postings. This thing can be flagged as spam? This is an interesting community. I will keep that in mind anyway. Thanks. – Chris Jun 08 '11 at 09:06
0

A very similar question was asked and answered here:

How do I determine whether it's 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

Community
  • 1
  • 1
jb.
  • 9,987
  • 12
  • 39
  • 38
0

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
  • 1,789
  • 3
  • 15
  • 26