I wrote an .htaccess file to remove .html from the end of file links, but it ended up opening the products directory instead of the products.html file. I want to find a way for it not to open the directory and instead open the file.
Right now, when I click on the link example.com/products/, it opens the directory, but I want it to open the products.html file instead. Also, when I click on the link example.com/products/example2, the page opens without any problem. What’s the solution?
Directory structure:
- index.html
- products.html
- products/
- example.html
- example2.html
.htaccess
file:
DirectoryIndex index.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.html [NC,NE,L]
RewriteCond %{THE_REQUEST} s/([^.]+).html[s?] [NC]
RewriteRule ^ %1 [R=301,L]
</IfModule>