Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I've built a cool mobile website/app using JQuery Mobile. I want to offer that to clients, but I want to use my own hosting.

Here's what I want to do

If a user uses a mobile device to visit client.com, I want them to see the contents of mysite.com/mobile/?app=1.

If a mobile user visits client.com/something, I want them to see mysite.com/mobile/detail.php?i=something&app=1.

Requirements

  • The browser should still show the url on client.com or at least m.client.com.
  • The redirect should not break Jquery Mobile (therefore iFrames are out of the question)
  • The redirect should be easy to set-up for my client. Ideally a copy and paste of some javascript code.

Here's what I've come up with

I've thought of something, but I'm not sure if it's going to work and IF it's going to work, whether it's a good solution.

  • A small javascript would detect a mobile device and redirect to m.client.com.
  • Cname m.client.com would redirect to m.mysite.com
  • m.mysite.com would point to mysite.com/mobile/
  • ?app=1 would be appended by PHP.

I'm not even sure if that's going to work, and it requires too much effort for my clients.

I am willing to use almost any combination of techniques to achieve this. Javascript, Jquery, DNS zoning, HTAccess or anything else that would be good for it.

What would be the best way to do such a thing?

share|improve this question
    
Fair enough. That would just require a simple mod rewrite. But I didn't yet do that, because I didn't think it would impact the solution. But you think it would make it easier? EDIT > A comment was here. It's gone now. Now it looks like I'm talking to myself. –  Vic V Jan 22 '13 at 13:03
    
backbone.js and a RESTful API for content. Handle device detection on the server side, that way it goes fast before any output is sent to the browser. This is a good PHP mobile detection script: github.com/serbanghita/Mobile-Detect –  Kenzo Jan 22 '13 at 19:46
    
I've checked it out, but backbone.js seemed slightly to complicated for my needs. Thanks anyway! –  Vic V Jan 27 '13 at 13:23
add comment

1 Answer

up vote 0 down vote accepted

I ended up doing it like this.

I ask my clients to create a file called mobile.php on their server. I provide them with about 7 lines of code, that CURLS the appropriate page from my server. The file also sends along context information, so mobile.php now functions as the complete mobile website. I then provide a javascript browser detection script. I do this with javascript, because this will be compatible with all other sites.

It may not be the most efficient way, but it did the job, while still honoring the requirements I wrote in the first post.

share|improve this answer
    
What happens for users with JavaScript off, or search engines? You can, and should, handle mobile detection on the server side. –  Kenzo Jan 27 '13 at 20:32
    
You're right. I guess I'll offer the php redirect and only use javascript as a fallback only if a client really doesn't have the proper access to the host. Thanks! –  Vic V Jan 28 '13 at 8:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.