I have a website which checks the user agent and loads a mobile version if needed. It loads http://www.mydomain.com/mobile.
But, like this website “stackoverflow”, there isn’t a subdomain: it’s just “stackoverflow.com” for the desktop and mobile version. How is this done?
Thanks
www is not a subdomain, it’s a host name. And what happens here is just DNS in action.
Let’s look up http://www.stackoverflow.com
This says: "
www.stackoverflow.comis an alias forstackoverflow.com, look upstackoverflow.comto know the IP address", so now we look up stackoverflow.comAnd there it is, the IP address. That’s part 1 of the story.
Regarding the technique SO uses to serve mobile and desktop versions using the same URL, because the StackExchange software that powers SO isn’t open source I can only quote Jeff Atwood, from a comment on a blog post regarding the mobile version
which leads me to the speculate that the desired rendering (mobile or desktop) is part of your session, and the page controller just applies another set of templates to the article contents, that are stored in a database.