How to run domain.com and m.domain.com from one install
To use separate templates I created plugin and within init() method I overwritten templatesPath variable. Seems to be working although you need to test it with other plugins as I have tested it with fresh Craft instance only.

public function init() {
    $templatesPath = craft()-&gt;templates-&gt;getTemplatesPath();

    if(craft()-&gt;request-&gt;isMobileBrowser()){
        $templatesPath .= 'mobile/';
    } else {
        $templatesPath .= 'desktop/';
    }

    craft()-&gt;templates-&gt;setTemplatesPath($templatesPath);
}


isMobileBrowser()

This example assumes that templates folder contains mobile and desktop folders. Both have a mirror template files structure. Also you don't need m.domain.com anymore.



But it you need m.domain.com you can use multi environment config variables (environmentVariables) or stick to the previous solution.

return array(
    '*' =&gt; array(
        'templatesPath' =&gt; 'desktop',
    ),
    'm.domain.com' =&gt; array(
        'templatesPath' =&gt; 'mobile',
    ),
);

public function init() {
    $templatesPath = craft()-&gt;templates-&gt;getTemplatesPath();

    if(craft()-&gt;config-&gt;get('environmentVariables')['templatesPath']){ //this line changed
        $templatesPath .= 'mobile/';
    } else {
        $templatesPath .= 'desktop/';
    }

    craft()-&gt;templates-&gt;setTemplatesPath($templatesPath);
}




To force mobile URL insert this code to desktop base layout file:

if(craft.request.isMobileBrowser()) {
    {% redirect 'http://m.domain.com' %}
}