title: htaccess RewriteRules not working on subdirectories
body: <p>I have a static HTML site that I'm trying to add some URL rewriting rules to via my .htaccess file.</p>
  
  <p>The site file directory looks like this:</p>
  
  <pre><code>- index.htm
  
  - about-us [subdirectory]
      - index.htm
  
  - careers [subdirectory]
      - index.htm
  
  - contact [subdirectory]
      - index.htm
      - map.htm
      - privacy.htm
  
  - projects [subdirectory]
      - index.htm
      - education.htm
      - healthcare.htm
      - recreation.htm
      - residential.htm
      - hospitality.htm
  
  - services [subdirectory]
      - index.htm
  </code></pre>
  
  <p>My goal is to remove the file extensions from the page URLs, append a trailing slash, and force a 301 redirect so that anyone trying to access the file in it's original format (i.e. <a href="https://example.com/projects/education.htm" rel="nofollow noreferrer">https://example.com/projects/education.htm</a>) would automatically be rewritten to it's cleaner format (i.e. <a href="https://example.com/projects/education/" rel="nofollow noreferrer">https://example.com/projects/education/</a>).</p>
  
  <p>I already have the index.htm files rewritten/redirected in the .htaccess file on the root of my site. Here's what I have so far:</p>
  
  <pre><code>DirectoryIndex index.php index.html index.htm
  RewriteEngine On
  
  RewriteCond %{REQUEST_URI} (.*)/$
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}\.htm -f
  
  RewriteRule ^(.+)/$ /$1/ [R=301,L]
  RewriteRule ^index\.htm$ / [R=301,L]
  RewriteRule ^(.*)/index\.htm$ /$1/ [R=301,L]
  </code></pre>
  
  <p>I have the directory root files (index.htm) removed successfully from the URLs, but for the life of me, I can't seem to get the non-root files (i.e. education.htm) rewritten in the desired format.</p>
  
  <p>Can anyone shed some light on what I'm doing wrong?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>As per @misorude's comment, I removed the 1st rewrite rule. I also changed the 301s to 302s (at least temporarily, to try and avoid rule caching issues). I also modified my existing rules to utilize the "+" character in my regex to force a real file or folder name in my rules.</p>
  
  <p>Finally, I added a new 3rd rule. This one is an attempt to find all subdirectory "non index" pages, and remove their file extensions, which appears to work. However, I'm getting 404 errors on those non index pages.</p>
  
  <p>All of my previously working index.htm rewrite rules are working just fine, but the non index ones throw 404 errors. Here's my update htaccess file:</p>
  
  <pre><code>DirectoryIndex index.php index.html index.htm
  RewriteEngine On
  
  RewriteCond %{REQUEST_URI} (.*)/$
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}\.htm -f
  
  # If we're on the root index page of the site, 
  # remove index.htm from URL
  RewriteRule ^index\.htm$ / [R=302,L]
  
  # If we're on a subdirectory index page, remove the index.htm from the URL
  RewriteRule ^(.+)/index\.htm$ /$1/ [R=302,L]
  
  # If we're on a non-index page of a subdirectory, 
  # remove the extension from the   URL
  RewriteRule ^(.+)/(.+)\.htm$ /$1/$2/ [R=302,L]
  </code></pre>
  
  <p>Any advice?</p>