title: Virtually chroot clients using mod_rewrite?
body: <p>I am attempting to setup a webdav website for various clients to upload/download files. However I don't want each client to see the other clients' data. Each client uses SSL client certificates to authenticate, so I would like to chroot them into their own directory tree.</p>
  
  <p><strong>For example:</strong>  </p>
  
  <ul>
  <li><a href="https://example.com/webdav/upload" rel="nofollow">https://example.com/webdav/upload</a>  </li>
  <li>Should map to filesystem location</li>
  <li>/somewebroot/webdav/SSL_USERNAME/upload</li>
  </ul>
  
  <p>I thought that I could use mod_rewrite for this but my rules seem to send me into an infinite redirection loop. Any thoughts?</p>
  
  <pre><code>Alias /webdav /somewebroot/webdav
  &lt;Directory /somewebroot/webdav&gt;
      RewriteEngine On
      RewriteBase /webdav
  
      RewriteCond %{SSL:SSL_CLIENT_S_DN_CN} ADMIN #The admin does not get chrooted
      RewriteRule .* - [L]
  
      RewriteCond %{REQUEST_URI} !^%{SSL:SSL_CLIENT_S_DN_CN}/(.*)
      RewriteRule ^(.*) %{SSL:SSL_CLIENT_S_DN_CN}/$1 [L]
  &lt;/Directory&gt;
  </code></pre>