Jump to content

Redirection to 'mobile version' - please help!


eattherich

Recommended Posts

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.