Mobile website without subdomain
===

I have a website which checks the user agent and loads a mobile version if needed. It loads 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