ReWrite rule doesn’t work for urls containing underscores

Hope somebody can figure this one out.

I have the following code for a WordPress static export site in my .htaccess file which redirects any request ending in .html to /index.html

gets redirected to

THAT works fine.

BUT... if the requested file with the .html includes an underscore I get a "too many redirects" error.

tries to connect

# Enable Rewrite module
RewriteEngine on
RewriteRule ^ - [E=rewrite:on]

# Check if requested file or directory already exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index\.html$

# Redirect all .html file requests to equivalent /index.html file request
RewriteRule ^(.*)\.html$ /subdirectory/$1/index.html [R=301,L]

# If the Rewrite module is not active then return a 404 error
RewriteCond %{ENV:rewrite} !on
RewriteRule ^ - [L,R=404]


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer