Forum Topic: Strip .html from url, but only for specific subdirectly

Forum: .htaccess Forum : Redirecting • Posted by Jeremy Hogan • Updated:

I am using the following in my htaccess file to remove the .html from the end of incoming urls and redirecting them to those urls without.

RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

This is working pretty well, but I actually want to exclude the wp-content and wp-includes subdirectories. It's preventing me from editing wordpress images because the tinymce wpeditimage uses iframed urls with .html appended.

So, how can I use this, but exclude specific directories. Thanks!

1 Reply to “Strip .html from url, but only for specific …”

Jeff Starr
Posted by Jeff Starr

Hi Jeremy,

Try this:

RewriteCond %{THE_REQUEST} !/wp-content/ [NC]
RewriteCond %{THE_REQUEST} !/wp-includes/ [NC]
RewriteCond %{THE_REQUEST} \.html [NC]
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

Should do the trick, test well! :)