On the server, I have a file (on the filesystem) called page.html, which I want to be accessed as site.com/page  So if someone goes to site.com/page.html, it should 301 redirect to site.com/pageI've seen rewrite rules that will handle rewriting /page -> /page.html internally, but forcing it to 301 redirect /page.html -> /page as well causes a redirect loop for me.The END flag looks like it can be used to do what I want, but it is not yet supported.I've also tried using ENV as follows:RewriteRule ^page$ /page.html [L,E=END:1]RewriteCond %{ENV:END} !1RewriteRule ^page.html$ /page [R=301,L]But that results in a redirect loop as well.
Remove extension from URL using a rewrite without resulting in a redirect loop
htaccess;301 redirect;mod rewrite;url rewriting
I asked this same question on StackOverflow.   To get it to work properly, you have to use environment variables:RewriteRule ^page$ /page.html [L,E=LOOP:1]RewriteCond %{ENV:REDIRECT_LOOP} !1RewriteRule ^page.html$ /page [R=301,L]This is because mod_rewrite does multiple passes through your rules.    During the first pass, it sets the environment variable.   During the second pass, it prepends the variable with the REDIRECT_ prefix, so you have to read it as REDIRECT_LOOP.