http://mobiledetect.net/
İçeride gerekli herşey mevcut sana bir Mobile_Detect.php dosyası veriyor nasıl kullanacağına dair gerekli kodlarda mevcut sitede..
Bu sebeple php kodlarını buradan yazma ihtiyacı duymuyorum.
Yok ben illede kendim yapıcam diyorsan buyur.
1. htaccess ile yaparsın
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "!(android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos)" [NC]
RewriteRule ^$ http://www.siteadresin.com/ [L,R=302]
2. Javascript ile yaparsın içinde ikiye ayrılır..
<script>
var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()))
if(mobile){
document.location="http://m.siteadresin.com/";
}</script>
Bağzıları da ekran çözünürlüğüne bakar..
<script>
</script>
BONUS ::
İlki ile aynı mantık ama daha karizma, yazmış adam dedirtiyor :)
function cihazKontrolu() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
){
return true;
}
else {
return false;
}
}
if (cihazKontrolu()==true){
window.location = “http://m.siteadresin.com/”;
}