title: .htaccess mod_rewrite issue
body: <p>Almost in any project I work on, some issues with .htaccess occur. I usually just find the easiest solution and leave it because I don't have any knowledge or understanding for Apache, servers etc. But this time I thought I would ask you guys.</p>
  
  <p>This is the files and folders in my (simplified) setup:</p>
  
  <pre><code>/modrewrite-test
      .htaccess
      /config
      /inc
      /lib
      /public_html
          .htaccess
          /cms
              /navigation
                  index.php
                  edit.php
              /pages
                  index.php
                  edit.php
          login.php
          page.php
  </code></pre>
  
  <p>The "config", "inc" and "lib" folders are meant to be "hidden" from the root of the website. I try to accomplish this by making a .htaccess-file in the root that redirects the user to "public_html". The .htacess-file contains this:</p>
  
  <pre><code>RewriteEngine On
  RewriteRule   (.*) public_html/$1
  </code></pre>
  
  <p>This works perfect. If I type "<a href="http://localhost/modrewrite-test/login.php" rel="nofollow noreferrer">http://localhost/modrewrite-test/login.php</a>" in my browser, I end up in public_html/login.php which is my intention. So this works fine. The .htaccess-file in "public_html" contains this:</p>
  
  <pre><code>RewriteEngine On
  
  # Root
  RewriteRule   ^$ page.php [L]
  
  # Login
  RewriteRule   ^(admin)|(login)\/?$ login.php [L]
  
  # Page (if not a file/directory)
  RewriteCond   %{REQUEST_FILENAME} !-d
  RewriteCond   %{REQUEST_FILENAME} !-f
  RewriteRule   ^(.*)$ page.php?url=$1 [L]
  </code></pre>
  
  <p>The first rewrite just redirects me to public_html/page.php if I try to reach "<a href="http://localhost/modrewrite-test/" rel="nofollow noreferrer">http://localhost/modrewrite-test/</a>". The next rewrite is just for the convenience of users trying to log in - so if they try to reach "<a href="http://localhost/modrewrite-test/admin" rel="nofollow noreferrer">http://localhost/modrewrite-test/admin</a>" or "<a href="http://localhost/modrewrite-test/login" rel="nofollow noreferrer">http://localhost/modrewrite-test/login</a>" they will end up at the login.php-file. The third and last rewrite handles the rest of the requests. If I try to reach "<a href="http://localhost/modrewrite-test/bla/bla/bla" rel="nofollow noreferrer">http://localhost/modrewrite-test/bla/bla/bla</a>" it will just redirect me to public_html/page.php (with the 'url' GET-variable set) instead of finding a folder called "la", containing a folder named "bla" and etc.</p>
  
  <p>All of these things work perfect but a minor issues occurs when I for instance try to reach "<a href="http://localhost/modrewrite-test/cms/navigation" rel="nofollow noreferrer">http://localhost/modrewrite-test/cms/navigation</a>" without a slash at the end of the URL. When I try to reach that page the browser is somehow redirected to "<a href="http://localhost/modrewrite-test/public_html/cms/navigation/" rel="nofollow noreferrer">http://localhost/modrewrite-test/public_html/cms/navigation/</a>". The correct page is shown but why does it get redirected and add the "public_html" part in the URL? The desired behavior is that the URL stays intact and that the page public_html/cms/navigation/index.php is shown.</p>
  
  <p>The files and folders in the (simplified) can be found at <a href="http://highbars.com/modrewrite-test.zip" rel="nofollow noreferrer">http://highbars.com/modrewrite-test.zip</a></p>