Reputation: 2222
I've noticed many sites use some strategy to host their two sites for pc and mobile users on only one url. For example, https://read.douban.com , its pc site and mobile site uses one url, how does this happen? Note I'm not asking the responsive design because its mobile site does use responsive design itself. And I don't think it is a nginx redirect because the urls are the same. There is one link on the mobile site to switch between the two sites. How does they make a single url host multiple websites? And how to switch between them? Thanks.
Upvotes: 0
Views: 550
Reputation: 141
If you separate the user request then you can hosting a single url to multiple websites?
So First detect the user request. NB: I only consider the incoming user request is from PC or other devices(Phone, Tab, etc..)
STEP 01: request is from PC
// return negative value if the request is from PC
var myNavigator = navigator.appVersion.indexOf("Mobile");
So, based on myNavigator
value, we make separate sites.
Tnx, Happy coding!
Upvotes: 1
Reputation: 335
I guess there are many ways. One way I know, is with Struts: Each request is going through Java logic and then an JSP page is sent to the user {This is a very simplified way to look at Struts}.
So, in this case a request comes from a mobile browser - will get a JSP made for mobile. A request from a PC will get a JSP for PC. The URL can stay the same.
Upvotes: 1