Options -Indexes
RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+(.*/)?index\.php[?/\s] [NC]
RewriteRule ^(.*/)?index\.php/?(.*)$ /$1$2 [R=301,L,NE]

RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[?\s] [NC]
RewriteRule ^(.+?)\.php$ /$1 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
