Is there anything I could do to improve the following .htaccess
code?
Options +FollowSymLinks
RewriteEngine On
# Redirect non-www to www.
# http://{domain}/
# http://www.{domain}/
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !=localhost [NC]
RewriteCond %{HTTP_HOST} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=::1
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirect trailing slash to non-trailing slash.
# http://www.{domain}/foo/
# http://www.{domain}/foo
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
# Redirect trailing ".php" to extensionless.
# http://www.{domain}/foo.php
# http://www.{domain}/foo
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+ [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+)\.php$ /$1 [R=301,L]
# Redirect "/index" to root.
# http://www.{domain}/index
# http://www.{domain}/
RewriteRule ^index$ / [NC,R=301,L]
# Forward to version with ".php" extension.
# http://www.{domain}/foo
# http://www.{domain}/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ /$1.php [L]