title: mod_rewrite to remove .php extension AND preserve GET parameters
body: <p>I have looked at these solutions and none of them actually work properly on my end:</p>
  
  <p><a href="https://stackoverflow.com/questions/1698464/mod-rewrite-to-remove-php-but-still-serve-the-php-file">mod_rewrite to remove .php but still serve the .php file?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/6534904/how-to-remove-file-extension-from-website-address">How to remove file extension from website address?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/12231650/how-to-use-apache-mod-rewrite-to-remove-php-extension-while-preserving-the-get">How to use Apache Mod_rewrite to remove php extension, while preserving the GET parameters?</a></p>
  
  <p>and they just don't do the following, which is what I need done:</p>
  
  <p>1) remove .php extension from files and instead of /index.php display /index</p>
  
  <p>2) preserve GET parameters (which I read and store in session cookies while the file is being loaded, in the header), so instead of /index.php?a=1&amp;b=2 display maybe /index/a1/b2</p>
  
  <p>3) work on subdomains and https:// without messing up the URL completely or ending up in an infinite loop or something...</p>
  
  <p>Does anyone have a clue how to put together these rules so they cover the 3 points above correctly?</p>
  
  <p>This is what I'm working with as a starting point:</p>
  
  <pre><code>RewriteCond %{THE_REQUEST} (\.php(.*)\sHTTP/1)
  RewriteRule ^(.+)\.php$ /$1 [R=301,L,QSA]
  </code></pre>