How to remove .html
from the URL of a static page?
Also, I need to redirect any url with .html
to the one without it. (i.e. www.exam
Resorting to using .htaccess
to rewrite the URLs for static HTML is generally not only unnecessary, but also bad for you website's performance. Enabling .htaccess
is also an unnecessary security vulnerability - turning it off eliminates a significant number of potential issues. The same rules for each .htaccess
file can instead go in a
section for that directory, and it will be more performant if you then set AllowOverride None
because it won't need to check each directory for a .htaccess
file, and more secure because an attacker can't change the vhost config without root access.
If you don't need .htaccess
in a VPS environment, you can disable it entirely and get better performance from your web server.
All you need to do is move your individual files from a structure like this:
index.html
about.html
products.html
terms.html
To a structure like this:
index.html
about/index.html
products/index.html
terms/index.html
Your web server will then render the appropriate pages - if you load /about/
, it will treat that as /about/index.html
.
This won't rewrite the URL if anyone visits the old one, though, so it would need redirects to be in place if it was retroactively applied to an existing site.