1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Anyone know how to redirect to a mobile site??

Discussion in 'General Scripting Chat' started by bingading, Aug 5, 2011.

  1. bingading

    bingading Registered Member

    Joined:
    May 23, 2011
    Messages:
    82
    Likes Received:
    53
    Occupation:
    trading and membership sites
    Location:
    BHW
    does anyone know of a simple way to detect the use of a mobile device and redirect it to a different website???

    Please help thanks!
     
  2. MickMcG

    MickMcG Power Member

    Joined:
    Feb 24, 2011
    Messages:
    600
    Likes Received:
    164
    are u using apache server? what type of landing pages are u using (dynamic/static)? give us more details and we might be able to help ;)
     
  3. bingading

    bingading Registered Member

    Joined:
    May 23, 2011
    Messages:
    82
    Likes Received:
    53
    Occupation:
    trading and membership sites
    Location:
    BHW
    I am using static pages. so i just want www.example.com to detect if i am using a mobile or not... if so redirect to m.example.com if not then stay at the www.
     
  4. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,227
    Occupation:
    Retired
    Location:
    Old Peoples Home
  5. _Chip_

    _Chip_ Senior Member

    Joined:
    Jun 28, 2009
    Messages:
    847
    Likes Received:
    256
    Occupation:
    Student
    Location:
    Depends on my vpn
    if you are using wordpress, there are free plugins available
     
  6. MickMcG

    MickMcG Power Member

    Joined:
    Feb 24, 2011
    Messages:
    600
    Likes Received:
    164
  7. MickMcG

    MickMcG Power Member

    Joined:
    Feb 24, 2011
    Messages:
    600
    Likes Received:
    164
    if they are static pages, u have two options, use the web server to redirect (best way) or add a javascript to your pages to detect and redirect (not so good and not seo friendly). check with your host what kind of server they are running?
     
  8. florflor

    florflor Senior Member

    Joined:
    Mar 9, 2008
    Messages:
    822
    Likes Received:
    307
    It's easy, just do it based on site width:

    put this in <head></head>:
    Code:
    <script type="text/javascript">
    <!--
    if (screen.width <= 699) {
    document.location = "http://m.site.com";
    }
    //-->
    </script>
    some browsers don't have JS on, you should stick something in noscript for that. not sure what though, there are some php you might use.

    I think most just use JS though.
     
  9. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,227
    Occupation:
    Retired
    Location:
    Old Peoples Home
    Its in there - but wouldn't of put it past them 'forgetting' :)

    Code:
    protected $devices = array(
            "android"       => "android",
            "blackberry"    => "blackberry",
            "iphone"        => "(iphone|ipod)",
            "opera"         => "opera mini",
            "palm"          => "(avantgo|blazer|elaine|hiptop|palm|plucker|xiino)",
            "windows"       => "windows ce; (iemobile|ppc|smartphone)",
            "generic"       => "(kindle|mobile|mmp|midp|o2|pda|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap)"
        );
    
     
  10. davids355

    davids355 Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 25, 2011
    Messages:
    8,802
    Likes Received:
    6,371
    Home Page:
    If you have trouble I have working example code I can send you.

    From my experience, make sure you redirect from mobile to non mobile as well - so desktop users don't see your mobile site.

    Also make sure you restrict your mobile sites so google crawler doesn't index (to avoid dupe content).
    Google also has a mobile bit as well so make sure you declare the mobile site accordingly.

    Lastly, I would advise to think about it carefully - I had a mobile site for a while but ended up scraping it as the mobile ads didn't generate any revenue, and when I think about it, with smart phones being so popular, most phones are quite capable of displaying a desktop page pretty well.

    So what I would say is make sure your mobile site really is providing and enhanced user experience compared to your desktop version.