eattherich Posted February 9, 2011 Share Posted February 9, 2011 Hey everyone! I'm an absolute beginner with PHP but in my struggle with a project, I keep seeing 'PHP' so here I am, asking for help from the experts. I have a client who wants a basic 'mobile version' of their website to be displayed automatically when people view it on a mobile device (iPhone, Android especially). I've tried a couple of JavaScript solutions but, for some reason, they wouldn't work on Android (despite the author of the code specifying that it 'should do'). This has led me to look into a server-side solution. If the user visits the site, e.g. www.mysite.com on a mobile device, I want it to redirect to the subdomain m.mysite.com (I could even use www.mysite.com/mobile). On this 'mobile version' there should be a link to view the full site (and vice versa). Does anyone know of any tried and tested methods to achieve this? I'm literally pulling my hair out now with this. Thank you so much in advance. Have a great day. Regards Darryl Quote Link to comment Share on other sites More sharing options...
anups Posted February 9, 2011 Share Posted February 9, 2011 You can use .htaccess file basically you'll have to expand on that .. what's happening here is all in the rewrite condition and rule - so to take an example from another blog: RewriteCond %{HTTP_USER_AGENT} “Windows CE” [NC,OR] #Windows CE and Pocket PC RewriteCond %{HTTP_USER_AGENT} “NetFront” [NC,OR] #PalmSource WebBrowser 2.0 RewriteCond %{HTTP_USER_AGENT} “Palm OS” [NC,OR] #Eudora Web Browser for Palm RewriteCond %{HTTP_USER_AGENT} “Blazer” [NC,OR] #Handspring Blazer Browser RewriteCond %{HTTP_USER_AGENT} “Elaine” [NC,OR] #RIM Devices RewriteCond %{HTTP_USER_AGENT} “^WAP.*$” [NC,OR] #WAP Browsers RewriteCond %{HTTP_USER_AGENT} “Plucker” [NC,OR] #Plucker Offline download client RewriteCond %{HTTP_USER_AGENT} “AvantGo” [NC] #AvantGo Service RewriteRule ^index.php http://m.yourdomain.com/ [L,R] basically if the browser's user agent matches one of these strings, then the rewrite rule kicks in... it's not the most basic of concepts and rewrite stuff can be quite touchy, so it could be tricky to implement, but that's how you'd go about it... hope that helps a bit! Quote Link to comment Share on other sites More sharing options...
eattherich Posted February 9, 2011 Author Share Posted February 9, 2011 Thanks for such a quick response, I'll have a look into that. I have a question about that method though: would it be possible to have a "view full site" link on the mobile site? Obviously I would like mobile users to view the mobile site primarily but some (with the latest smartphones) might want to view the site in 'all it's glory' - is this possible? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.