Mobile redirect script please

elviswong

Senior Member
Joined
Nov 8, 2011
Messages
983
Reaction score
276
Guys
I'm looking for a redirect script or something that can redirect mobile traffic going to my "PC/Laptop" created web sites.
No need to show them this content. Worthless...

Something that detects if it's a mobile, then redirects depending of the country of origin, to the site/offer (whatever i wish) that fits.

Ex:

Guy from USA passes by one of my site using an Iphone, scripts knows he's using a mobile, sends him to a UsaMobileUser.mysite.com instead of www.mysite.com.
On this, offer/or anything that fits an American using a mobile.

CanadianMobileUser.mysite.com
UkMobileUser.mysite.com

and so on and so on..

THANKS
 
This can be done loads of different ways, have a look at this site and implement the code that is best suited for your site. detectmobilebrowsers(.)c0m/
 
You can simply do it by redirecting based on the useragent. Check the first answer here: http://stackoverflow.com/questions/9624644/php-redirect-to-mobile-version-if-user-browses-to-subdomain
 
You can simply do it by redirecting based on the useragent. Check the first answer here: http://stackoverflow.com/questions/9624644/php-redirect-to-mobile-version-if-user-browses-to-subdomain

Simple code..? Take mine...

$aG=array('iphone','android','webos','blackberry','ipod','mobile');
$aD=0;foreach($aG as $aG){if(stripos(strtolower($_SERVER['HTTP_USER_AGENT']),$aG)){$aD=1;}
}if($aD==1){echo'<script>window.location="http://mobile.mysite.com"</script>';}
 
Last edited:
Redirect through .htaccess:

RewriteEngine On
RewriteCond %{HTTP_ACCEPT_LANGUAGE} de.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} de-ch.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} at.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} en-gb.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} de-at.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} de-li.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} fr-ch.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} ch.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} de-de.* [NC,OR]
RewriteRule .* НТТР://dомаin.сом [R,L]

Redirect through JavaScript:

<script language="JavaScript">
var language1, language2, i, f;
var loc = new Array("at","au","be","ca","dk","es","fi","gr","ch","de-ch","de","fr","en-ie","ie","en-gb","nl","it","gb","no","pt","nz","us");
if (navigator.appName.indexOf("Microsoft") != -1) {
language1=navigator.systemLanguage.toLowerCase();
language2=navigator.userLanguage.toLowerCase();
} else { language1=language2=navigator.language.toLowerCase(); }
for (f=false,i=0;i || (language2 == loc)) { f = true; break; } }
if (f) document.location="НТТР://dомаin.сом";
</script>

All specified users (registered) zones will be redirected, not indicated-to remain on the page.
See more: munkyonline(DОТ)co(DОТ)uk/articles/htaccess-301-redirects-for-ip-ranges
 
copy and paste just above your homepage </head> tag. replace yourwebsite.com with your own. If you've changed the name of the 'mobile' folder, make the changes below .
<--




<script type="text/javascript">
if(screen.width < 600){
window.location = "http://yoursite/mobile/index.html";
}
</script>

</head>
<body>
 
here is the .htaccess redirect that I use:
webdesignandsuch[dot]com/redirect-to-a-mobile-site-with-htaccess-and-set-a-cookie-to-break-redirect/

So far this is the best one I found
 
with new samsung s3 phones i had to change value from 600 to 800

copy and paste just above your homepage </head> tag. replace yourwebsite.com with your own. If you've changed the name of the 'mobile' folder, make the changes below .
<--




<script type="text/javascript">
if(screen.width < 600){
window.location = "http://yoursite/mobile/index.html";
}
</script>

</head>
<body>
 
Back
Top