Last Updated on April 20, 2021 by Amit

htaccess remove html from URLs

htaccess rule to remove .html file extension from URLs

A 100% working and tested rule to trim .html from URLs .
You can just copy and paste it to your .htaccess or server.config files on Apache server.

RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+).html [NC]
RewriteRule ^.+$ /%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^/?(.+)/?$ /$1.html [L]

The RewiteRule above will convert all your URLs from




If you want to add a traling slash (a / at the end) to your new non-html URL forexample

example.com/file/ then just put a traling slash at the end of the destination path of the first rule .

Change the first RewriteRule line to

RewriteRule ^.+$ /%1/ [R=301,L]

This will automatically force a traling slash on your html URLs and your URL example.com/fileName.html will get redirected to example.com/fileName/ .

Where to put the RewriteRule on Apache server

You can use it either in your .htaccess or server.config file.

In case you don’t have access to the main server.config file on your server then it’s ok to use it in htaccess file.
You can use the rule in your public_html/.htaccess so that it can apply to all folders and subfolders.

If you don’t want the rule to apply to a specific sub directory then create a seprate .htaccess file with the following single line contents
RewriteEngine on and save the file. Then your public_html/.htaccess will not affect the subdirectory.

Also see this : How to remove .php extension from URLs .

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.