简体   繁体   中英

How to make a single url host multiple websites?

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.

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM