title: .htaccess rewrite file uri to either file-name.html or file-name.php - whichever exists
body: <p><strong>OBJECTIVE:</strong> To cause the browser to rewrite to file-name.php, if it exists; else return file-name.html - whether the visitor has typed the url as any one of the following:</p>
  
  <ol>
  <li><code>http://mydomain.com/file-name</code></li>
  <li><code>http://mydomain.com/file-name.html</code></li>
  <li><code>http://mydomain.com/file-name.php</code></li>
  </ol>
  
  <p>Had good success with the following rules in my .htaccess file at root:</p>
  
  <pre><code># REWRITE FILE URI TO file.php IF EXISTS
  Options Indexes +FollowSymLinks +MultiViews
  Options +ExecCGI
  RewriteEngine on
  RewriteBase /
  # parse out basename, but remember the fact
  RewriteRule ^(.*).html$ $1 [C,E=WasHTML:yes]
  # rewrite to document.php if exists
  RewriteCond %{REQUEST_FILENAME}.php -f
  RewriteRule ^(.*)$ $1.php [S=1]
  # else reverse the previous basename cutout
  RewriteCond %{ENV:WasHTML} ^yes$
  RewriteRule ^(.*)$ $1.html
  </code></pre>
  
  <p>However, I have since installed WP at root, alongside pre-existing website, and these rules are no longer working.</p>
  
  <p><strong>WHAT DOES WORK:</strong> <code>file-name</code> is rewritten to either <code>file-name.html</code> or <code>file-name.php</code> - whichever file exists.</p>
  
  <p><strong>WHAT DOES NOT WORK:</strong> <code>file-name.html</code> is not rewritten to <code>file-name.php</code> even when there is no <code>file-name.html</code> and <code>file-name.php</code> is there. Also, <code>file-name.php</code> is not rewritten to <code>file-name.html</code> when there is no <code>file-name.php</code> but there is <code>file-name.html</code>.</p>
  
  <p>The entire .htaccess as it is now:</p>
  
  <pre><code># BEGIN WP MULTISITE RULES
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  
  # uploaded files
  RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
  
  # add a trailing slash to /wp-admin
  RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
  
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]
  RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
  RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
  RewriteRule . index.php [L]
  # END WP MULTISITE RULES
  
  # REWRITE FILE URI TO file.php IF EXISTS
  Options Indexes +FollowSymLinks +MultiViews
  Options +ExecCGI
  RewriteEngine on
  RewriteBase /
  # parse out basename, but remember the fact
  RewriteRule ^(.*).html$ $1 [C,E=WasHTML:yes]
  # rewrite to document.phtml if exists
  RewriteCond %{REQUEST_FILENAME}.php -f
  RewriteRule ^(.*)$ $1.php [S=1]
  # else reverse the previous basename cutout
  RewriteCond %{ENV:WasHTML} ^yes$
  RewriteRule ^(.*)$ $1.html
  </code></pre>
  
  <p>Any advices? </p>