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

e.g.
/subdirectory/pageexists.html
gets redirected to
/subdirectory/pageexists/index.html

THAT works fine.

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

e.g. 
/subdirectory/page_exists.html
tries to connect
/subdirectory/subdirectory/subdirectory/page_exists/index/index/index.html

# 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