Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Redirect users if on desktop to new URL

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #44212
    Anonymous
    Inactive

    How can i automatically redirect users if they are on a desktop/laptop to a different URL.

    #132284
    Paulie_D
    Member

    Isn’t it usually done the other way round?

    If they are on mobile send them to a specific mobile site?

    #132287
    pixelgrid
    Participant

    you can use user agent detection with php on the serverside or with javascript on the client side.
    With php the users user agent is stored in

    $_SERVER

    you can go with regex or strpos and testing for the devices you want and redirect with

    header(‘Location: http://example.site.com/’)

    Respsonsive design is always better though

    #132290
    Anonymous
    Inactive

    @Paulie_D i Guess i could put up the desktop site and redirect to mobile if on mobile. So either way could work.


    @pixelgrid
    That sounds kinda hard and i don’t know PHP or JavaScript.

    #132291
    pixelgrid
    Participant

    you can find many scrips using php online

    just for the record im posting an .htaccess solution too

    RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
    RewriteRule ^(.*)$ http://ipad.yourdomain.com [R=301]

    this one is for ipad redirection only

    #132292
    Alen
    Participant

    http://mobiledetect.net/

    Include the Class in your project. If on WordPress that would be in your functions.php file.

    Then just:

    $detect = new Mobile_Detect();

    if ($detect->isMobile()) {
    header(‘Location: http://mobile.site.com/’)
    }

    If you want the opposite just use the logical operator Not `!`.

    if (!$detect->isMobile()) {
    header(‘Location: http://desktop.site.com/’)
    }

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘CSS’ is closed to new topics and replies.