title: apache htaccess rewrite https request_filename
body: <p>I am looking to optimize some rewrite rules for better loading performance. I am hoping to combine rules to rewrite from HTTP to HTTPS as well as handle rewriting of the filename for GET var.</p>
  
  <p>This is the functioning code:</p>
  
  <pre><code>RewriteEngine on
  
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  
  RewriteRule ^(.*)$ index.php?var=$1 [L,QSA]
  </code></pre>
  
  <p>This was my attempt, which was redirecting to only the %{REQUEST_URI}:</p>
  
  <pre><code>RewriteEngine on
  
  RewriteCond %{HTTPS} off
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ https://%{HTTP_HOST}index.php?var=$1 [R,L,QSA]
  </code></pre>