title: How can I remove file extensions for clean URLs with .htaccess, but with file and subdirectory having same name?
body: <p>I have a site created with a static site generator, and a structure as follows:</p>
  
  <pre><code>- index.html
  - products.html
  - products [directory]
      * product-a.html
      * product-b.html
  </code></pre>
  
  <p>I am trying to create a .htaccess file that will rewrite the URLs to remove the .html extensions. I have this working just fine, but my problem is when there is a "file.html" and a directory named "file". When this occurs, I am getting an error when trying to view /file.</p>
  
  <p>My desire is to have <strong>mysite.com/products</strong> be the main product listing page, and have <strong>mysite.com/products/product-a</strong> be the URL to the specific product detail page.</p>
  
  <p>A workaround that I don't think is desirable would be to make my products.html file as index.html within the products directory. That doesn't feel right, though, and I'm sure there would be SEO consequences due to confusing structure.</p>
  
  <p>Here is my current .htaccess mod_rewrite section:</p>
  
  <pre><code>AddType text/x-component .htc
  RewriteEngine On
  RewriteBase /
  
  # remove .html; use THE_REQUEST to prevent infinite loops
  RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
  RewriteRule (.*)\.html$ $1 [R=301]
  
  # remove index
  RewriteRule (.*)/index$ $1/ [R=301]
  
  # remove slash if not directory
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} /$
  RewriteRule (.*)/ $1 [R=301]
  
  # add .html to access file, but don't redirect
  RewriteCond %{REQUEST_FILENAME}.html -f
  RewriteCond %{REQUEST_URI} !/$
  RewriteRule (.*) $1\.html [L]
  </code></pre>
  
  <p>I am also looking for this solution to work with multiple nested levels working the same way. Is there a simple solution I am overlooking? Perhaps someone who has more experience with writing .htaccess files would be able to point me in the right direction.</p>
  
  <p>Any help is greatly appreciated!</p>