title: Apache .htaccess redirect if folder not present
body: <p>I have a website where I need to do the following</p>
  
  <p>if <a href="http://example.com/user1" rel="nofollow">http://example.com/user1</a> does not exist, redirect the user to <a href="http://user1.example.com" rel="nofollow">http://user1.example.com</a></p>
  
  <p>Similarly <a href="http://www.example.com/user2" rel="nofollow">http://www.example.com/user2</a> should redirect to <a href="http://user2.example.com" rel="nofollow">http://user2.example.com</a></p>
  
  <p>Is this possible using an .htaccess file?</p>
  
  <pre><code>RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*) http://%{HTTP_HOST} [R]
  </code></pre>
  
  <p>The above redirects to the home page, but how do I read the URL after / and do the redirect as above?</p>