title: .htaccess Regex Match File with Extensions or no Extension
body: <p>Basically I want to match any of the patterns below for the file path after the protocol through to the file name, even the file doesn't have an extension. </p>
  
  <p>I almost got there, but once I try to make it match files without an extension, it matches until the rest of the line.</p>
  
  <p>My test strings</p>
  
  <pre><code>http://regexr.com/foo.html?test (//regexr.com/foo.html)
  
  http://regexr.com/foo?test      (//regexr.com/foo)
  
  http://regexr.com/foo.php?test  (//regexr.com/foo.htm)
  
  http://regexr.com/foo.htm?test  (//regexr.com/foo.htm)
  </code></pre>
  
  <p>My current expression is <code>\/(.+)\.php</code> but this doesn't match the second file path without the extension, and if I make the last collection optional, it selects through the GET parameters. Any help would be much appreciated.</p>
  
  <hr>
  
  <p><strong>EDIT</strong> Below is my .htaccess block that I'm attempting to modify</p>
  
  <pre><code>RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{THE_REQUEST} \ /(.+)(\.php|\.html?)
  RewriteRule ^ /%1.aspx [L,R=301]
  RewriteRule ^(.*).aspx$ $1.php [QSA]
  </code></pre>
  
  <hr>
  
  <p><strong>FURTHER EDIT</strong>
  As pointed out, this may have been better asked as a redirect question. (Another note, I removed the html redirect since it causes a performance hit, so files with the extension <code>*.php</code> are the only files being redirected.)</p>
  
  <p>These are how I would like to have the files handled; 301 redirecting to the new address and then continuing to be processed as PHP by the server as such:</p>
  
  <pre><code>http://regexr.com/foo.html (Doesn't redirect, not processed)
  http://regexr.com/foo      (R to /foo.aspx, processed as /foo.php)
  http://regexr.com/foo.php  (R to /foo.aspx, processed as /foo.php)
  http://regexr.com/foo.htm  (Doesn't redirect, not processed)
  http://regexr.com/foo.aspx (Doesn't redirect, processed as /foo.php)
  </code></pre>