What's your current cookie setup?
Optimally what should happen is: When someone first arrives at the site, they should be sent to the desktop or mobile version based on their UA,
unless there's already a cookie expressing a preference. Every page should have a small unobtrusive-- but not invisible --link to the other version. And when your user goes to another page on the site, they should be kept on the same version, desktop or mobile.
It is just as easy to redirect all page requests as it is to redirect index-page alone. You already have-- or should have --the same type of code in place; it's what you use in your domain-name-canonicalization redirect. Essentially you're capturing the whole request and then sending them along to the appropriate (sub)domain.
The directory structure is not the same, though it could easily be if it makes things easier.
Yes, yes, yes. If you can possibly do this, it would make everything enormously easier.
Structurally you need something like this:
RewriteCond {check for cookie and see what it says}
RewriteCond {check whether (sub)domain matches cookie}
RewriteCond {check User-Agent}
RewriteRule {take action}
Unfortunately you can't do if/else loops in mod_rewrite alone. So you either have to make a series of rules covering all possibilities, or take a preliminary detour to a php script that checks everything:
--is cookie present?
--if yes, what does it say?
--which subdomain was requested?
and then:
--if cookie is present, does request agree with its setting?
--if there is no cookie, does request agree with user-agent?
Note that if the cookie is present, you do not need to check the user-agent at all. The user has already made a choice. Happily this is both good for your visitors-- because they're getting what they want --and also good for your server --because it doesn't have to do as much work :)