How to Hide .html Extension from Website URLs (Using .htaccess)
This guide explains how to remove the .html extension from website URLs using Apache rewrite rules in the .htaccess file.
After applying this configuration:
-
https://example.com/page.html➝ automatically becomeshttps://example.com/page -
The page will still load correctly without changing file names
Steps to Hide .html Extension
- Locate the
.htaccessfile
Path:public_html/.htaccess
If the file does not exist, create one
Add the following rewrite rules
Add these rules below any existing rewrite rules in the.htaccessfile:RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
- Save the file
Save changes
Clear browser cache or use Incognito mode