title: Htaccess Rewrite Rules and Conditions
body: <p>I have started yet another little project for personal uses, and I am setting up my web root htaccess file. I haven't touched this stuff for too long so I am having some issues with it.</p>
  <p>I will show some examples of what I want to do because I don't know how to explain it well.
  My webroot contains:</p>
  <p>/index.php</p>
  <p>/test/test.txt</p>
  <p>If the url is example.com/home, it should output example.com/index.php?page=home. That is pretty easy to do and I don't have any issue with it. The issue starts with the existing files.
  If the url is example.com/test or example.com/test/test.txt, I want it to output example.com/index.php?file=test or example.com/index.php?file=test/test.txt
  These are the conditions and rules in my htaccess file (these are meant for the existing files only):</p>
  <pre><code>RewriteCond %{REQUEST_FILENAME} !-f [OR]
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ - [S=1]
  RewriteRule ^(.*?)$ /index.php?file=$1 [L,QSA]
  </code></pre>
  <p>However, when I enter example.com/test, it goes straight to the directory &quot;test&quot; and the same with example.com/test.txt - just displays the file.</p>
  <p>First of all, is it alright to do this? And if so, how can I achieve this?
  Thanks in advance!</p>
  <p>P.S. How do I log the processing of my rewrite rules? I found that I can do this by modifying LogLevel in httpd.conf. I had it set to LogLevel alert rewrite:trace6, but the errorlog doesn't seem to contain the logs I need.</p>