title: Mobile website redirection based on user agent
body: <p>Say I've got two distinct domains:</p>
  
  <pre><code> 1) http://sub.test.org
   2) http://m.sub.test.org
  </code></pre>
  
  <p>for my website.</p>
  
  <p>I want domain n.1 to be associated to the full-version of my website (intended to be mainly visited by desktop user agents) and domain n.2 to be associated to its mobile-version (intended to be mainly visited by mobile user agents).</p>
  
  <p>Both of the versions reside on an external host which runs an instance of Apache webserver I can't control directly, but I am able to post <code>.htaccess</code> files and therefore I want them to control domain redirecting stuff (I don't want to use Javascript neither PHP server-side logic)</p>
  
  <p>The directory structure on the external host is, say:</p>
  
  <pre><code>directory / --&gt; contains full-version website's pages and resources 
                  (index.html is the entry-point)
  
  directory /mobile --&gt; contains full-version website's pages and resources 
                        (index.html is the entry-point)
  </code></pre>
  
  <p>and the mappings are:</p>
  
  <pre><code>http://sub.test.org -&gt; /index.html
  http://m.sub.test.org -&gt; /mobile/index.html
  </code></pre>
  
  <p>Now, my desired scenarios are as follows:</p>
  
  <p>A) When user asks for URL <code>http://sub.test.org</code>:</p>
  
  <ol>
  <li>IF current URL is <code>http://m.sub.test.org/*</code> (this means: if user is currently into the mobile-version) THEN serve page <code>http://sub.test.org/index.html</code></li>
  <li>ELSE:
  <ol>
  <li>IF user agent is mobile THEN redirect to URL <code>http://m.sub.test.org</code></li>
  <li>ELSE serve page <code>http://sub.test.org/index.html</code></li>
  </ol></li>
  </ol>
  
  <p>B) When user asks for URL <code>http://m.sub.test.org</code> - no matter what the user agent is - user should be redirected to URL <code>http://sub.test.org</code>.</p>
  
  <p>My questions:</p>
  
  <ul>
  <li>What would be the syintax of the associated <code>.htaccess</code> file? </li>
  <li>Do I need more than one? </li>
  <li>Where should I place it/them ?</li>
  </ul>
  
  <p>Any help/code hint would be really appreciated, because I have really a few experience with Apache <code>.htaccess</code> files and regexps! Thanks in advance.</p>