How to hide .html extension from the website url
.htaccess, apache, mod-rewrite, php, url-rewriting
Solution
You have your rule reversed (the first one would work otherwise):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [L]
Your original rule was `RewriteRule ^(.*)\.html$ $1 [L]` which translates to "If the requested resource name ends with `.html` then issue a redirect to the browser telling it to ask us if we have anything at the same name without the HTML". This results in a 404 (since Apache doesn't have anything to serve for the `.html`'less resource).
By switching the `.html` to the destination `RewriteRule ^(.*)$ $1.html [L]` we change the rule to say "If the requested resource name is not a file or directory on disk then try to re-route the request (internally, don't tell the browser) as if it ended in `.html`".
Problem
I know this question has been asked before but does anyone know of a good way to hide .html extensions. I've tried many of codes & many of the answers from the https://stackoverflow.com/ but am not seeing the result. Thats y I ask u again I've a static website and I wanted to remove the extension to clean my urls. I was working with static html files. Prior to removing the extension, the url would read `website.com/about.html`. With the extension removed, it would look like website.com/about. Hope that was clear. I've a .htaccess file and I tried many of the codes but it dosen't work. Here are some codes ``` RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)\.html$ /$1 [L,R=301] RewriteCond %{THE_REQUEST} \ /(.+/)?index(\.html)?(\?.*)?\ [NC] RewriteRule ^(.+/)?index(\.html)?$ /%1 [R=301,L] RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^(.+)\.html$ /$1 [R=301,L] RewriteCond %{SCRIPT_FILENAME}.html -f RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L] RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/ RewriteRule ^index\.html$ http://%{HTTP_HOST}/ [R=301,L] RewriteEngine On RewriteBase / RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^(.*)$ $1.html [NC,L] RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html RewriteBase / RewriteEngine on RewriteRule ^(.*)\.htm$ $1.html [nc] RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [L] ``` however I am not seeing any results...:(