title: htaccess remove .php extension and rewrite to www
body: <p>I'm trying to accomplish 2 things in htaccess that is located in my root directory and should affect all web pages throughout my website.  I'm using Apache 2.4.</p>
  
  <p>1) Rewrite non-www to www (this part is currently working)</p>
  
  <p>2) Remove .php extension from URL</p>
  
  <p>For #2 I found two threads about this but when trying to implement it with code from #1 it never seems to work.  </p>
  
  <p><a href="https://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess">Remove .php extension with .htaccess</a></p>
  
  <p><a href="https://stackoverflow.com/questions/1992183/how-to-hide-the-html-extension-with-apache-mod-rewrite">How to hide the .html extension with Apache mod_rewrite</a></p>
  
  <p>Here is my code, the first part works fine but the second part doesn't seem to do anything for me as ".php" still shows up on all URL's.</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{HTTP_HOST} !^$
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteCond %{HTTPS}s ^on(s)|
  RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  
  RewriteCond %{REQUEST_FILENAME}.php -f
  RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
  </code></pre>
  
  <p>I also looked at this thread and tried the following, still not working.</p>
  
  <p><a href="https://stackoverflow.com/questions/32749003/5-htaccess-rewrites-force-https-remove-index-php-remove-php-force-www-for">5 .htaccess Rewrites: Force HTTPS, Remove index.php, Remove .php, Force www, Force Trailing Slash</a></p>
  
  <pre><code>RewriteEngine On
  RewriteBase /
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)\.(?!js|css)([^.]*)$ $1\.php
  
  RewriteCond %{HTTP_HOST} !^$
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteCond %{HTTPS}s ^on(s)|
  RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  </code></pre>
  
  <p>Any help would be appreciated.  Thanks in advance.</p>
  
  <p><em>UPDATED</em></p>
  
  <p>Here is the folder structure and where the PHP code exists.  Most php files are in the root folder but there are two additional folders that contain PHP code.</p>
  
  <pre><code>/
  index.php
  file1.php
  file2.php
  file3.php
  file4.php
  folder1/file5.php
  folder1/file6.php
  folder2/file7.php
  folder2/file8.php
  </code></pre>