RewriteCond %{REQUEST_URI} !^/folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^.*$ $0.php [L,QSA]
RewriteCond %{REQUEST_URI} !^/folder/
RewriteCond %{THE_REQUEST} (\S+)\.php
RewriteRule ^ %1 [R=301,L]