23
loading...
This website collects cookies to deliver better user experience
https://example.com/about.html
. Specifically, the .html
part is the problem here as most people would prefer to see https://example.com/about
instead. It’s nicer, don’t you think?https://test.kq.md
. Let’s visit the about page and see what happens…https://test.kq.md/about.html
is no good. The first solution for removing the HTML extension from the URL is simple – put the page in a folder.|-- 📄 index.html
|-- 📄 about.html
/about.html
to /about
simply create a folder called about
, move about.html
into that folder and rename it to index.html
. Once those changes are made, the new folder structure should look something like this:|-- 📄 index.html
|-- 📁 about
|-- 📄 index.html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.html
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
.html
from the URL path. It will also redirect anyone who visits a URL with .html
appended to it, so you shouldn’t get any 404 errors if people visit the full URL.23