Reputation: 23
Having an issue here while trying to remove .html extension from the url. I have work.html file and work folder on the same level. I'm tying to do rewrite in htaccess file, so it would work this way:
if someone hits URL .com/work -> it would load work.html page from the root directory. if someone hits URL .com/work/blabla -> it would load blabla.html page from work directory (.com/work/blabla.html)
But at the minute, when someone hits .com/work browser redirects to .com/work/ (work folder) and shows forbidden message. All other pages works as expected, the only issue is with the file and folder having the same name.
My rules are:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Could anyone help me with this?
ADDITION: On the picture below is file structure
after adding rewrites all works:
mywebsite.com -> show index.html
mywebsite.com/contact -> show contact.html
mywebsite.com/work/avrica - > show /work/avrica.html
the issue I have:
mywebsite.com/work -> which supposed to show work.html, but in reality it shows work folder with message forbidden
Upvotes: 2
Views: 83
Reputation: 784998
You can just use this single rule in your site root .htaccess:
DirectorySlash Off
Options -Indexes
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
Upvotes: 3