- This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
How can i automatically redirect users if they are on a desktop/laptop to a different URL.
Isn’t it usually done the other way round?
If they are on mobile send them to a specific mobile site?
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
@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.
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
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/’)
}