0

If I create two versions of my site, one normal and one in a folder on the server called "mobile" how can I then listen out for mobile devices and direct the user to the mobile folder?

Nate
  • 30,286
  • 23
  • 113
  • 184
Rex89
  • 153
  • 1
  • 3
  • 12
  • 2
    Duplicate of http://stackoverflow.com/questions/4483180/how-to-rewrite-to-mobile-myurl-com-if-user-is-mobile-use-apache-or-inside-weba – mkoistinen Apr 26 '12 at 17:43
  • many website have set browser name as class for HTML.chrome by default have class chrome on html tag. you can set those class for making fluid layout,also you can use server side redirection from request-header made from browser or device. – Chinook Apr 26 '12 at 18:53

1 Answers1

0

Your landing page will need to detect and redirect. With javascript this can be done as easily as:

// note this regex is probably **not** the 
// best one to use for mobile user agent detection
if(navigator.userAgent.match(/ios|android|windows phone/)) {
    window.location = 'http://mysite.com/mobile';
}

If you are using a server side technology you may do your redirect there as it is the preferred method, since most mobile devices can disable javascript. See the answer here for example on how to do this with apache.

Community
  • 1
  • 1
Nate
  • 30,286
  • 23
  • 113
  • 184
  • This kind of skips over the hard part... *How* do you know *who* to direct *where*? Generally you'd use User Agent sniffing or the user's screen resolution to decide. – Jasper Apr 26 '12 at 18:12