Akash
Akash

Reputation: 65

Webpage redirect for mobile user?

I have a website. I want any user that visits my website to be redirected to some different website designed for mobile. For instance: https://m.mywebsite.com

What can I do? I think there is number of way like through which this can be done
1)using javascript
2)using php
3)using meta tag
etc, etc

Can anyone suggest me what to use?

Upvotes: 0

Views: 3006

Answers (2)

Gerrit Sedlaczek
Gerrit Sedlaczek

Reputation: 1291

JavaScript

You could use this little script:

<script type="text/javascript">

  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)
    ) {} else {
    self.location = "m.mywebsite.com";
  }

</script>



PHP

I didnt try using a serverside solution yet, but it seems like php is capable of retrieving the userAgent information as well. By doing so a user from on a mobile platform would not have to download all the documents associated with your PC-version such as large images.

The PHP solution would look similar to the javascript attempt and would use

header("location: m.mywebsite.com");

inststead of

self.location = "m.mywebsite.com";

see: http://php.net/manual/de/function.get-browser.php

Upvotes: 1

Abid Soufiane
Abid Soufiane

Reputation: 31

Yes can you using javascript for check width of screen

<script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "mobile.html";
}
//-->
</script>

if you want to use sub domain lik this m.domainname.com , create sub domain and put your template

more

Redirect Mobile Devices

Detecting and Redirecting Mobile Users

Upvotes: 0

Related Questions