title: .htaccess mod_rewrite subdirectory to URL parameter
body: <p>I hope this was not asked over and over again before, but I didn't get further to an answer using google, w3schools and so on. So here is my question:
  I'm writing a script that creates kind of an index of projects that I have on my homepage and makes a nice list with images and teaser text based on an info file. I mostly have my projects on github and the readme is in markdown so I thought I could dynamically generate the HTML from the markdown of the latest blob from github on demand using PHP so it gets updated automatically.
  My directory structure looks like this:</p>
  
  <pre><code>projects
      project1
          .remoteindex
          .info
      project2
          .remoteindex
          .info
      index.php
      .htaccess
  </code></pre>
  
  <p>So when just <code>domain.tld/projects/</code> is requested I get the info from <code>.info</code> and make a nice index of all projects. But if <code>domain.tld/projects/project1/</code> is request it, I want to internally redirect it to <code>domain.tld/projects/?dir=project1</code> to do my markdown parsing and so on. But <code>domain.tld/projects/project1/image.png</code> should not be redirected.</p>
  
  <p>This is what I tried:</p>
  
  <pre><code>.htaccess
  RewriteEngine on
  RewriteRule ^([^/]+)/?$ index.php?dir=$1 [R,L]
  </code></pre>
  
  <p>I made it redirect instead of rewrite so that I can see what the error is because I just got an 404. The URL that I get redirected to is <code>domain.tld/home/www/web310/html/projects/index.php?dir=project1</code> so obviously there is something going wrong with the internal structure of the web server an paths an whatever.
  I hope you can understand my problem an I would be very pleased if someone could help me, because I'm totally lost on <code>.htaccess</code> anyway.</p>
  
  <h3>Edit:</h3>
  
  <p>See my answer below for the used <code>.htaccess</code>.</p>
  
  <p>The strange thing is that if I have an <code>index.html</code> in on of the subdirectories, my local web server (Apache with XAMPP for Mac OS X 1.7.3) does not rewrite and the <code>index.html</code> gets displayed, without one it works correctly.But on my real web server that serves my homepage it rewrites both with and without <code>index.html</code> (which is what I want). Any hints on that?</p>