Htaccess redirect from ‘/%postname%.html’ to ‘/%postname%’

Above the WordPress rewrite rules add:

RedirectMatch permanent ^/([^/]+)\.html$ /$1

That will catch example.com/foo.html but not example.com/travel-guides/foo.html. To catch all URLs ending with .html remove the first ^ from the pattern.

To redirect all URLs ending with .html except those in travel-guides you need mod_rewrite:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !^/travel-guides/
RewriteRule ([^/]+)\.html$  /$1 [L,R=301]

Leave a Comment