Forum Moderators: phranque
# Redirect direct client requests for /index.php in any directory to "/" in that directory
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/?#\ ]+/)*index\.php([?#][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]
#
# Redirect direct client requests to remove .php extensions
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?#\ ]+\.php([?#][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.example.com/$1 [R=301,L]
#
# Redirect all non-blank non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]