Forum Moderators: phranque
RewriteEngine on
#
# Externally redirect direct client requests for index page filepaths to "/" URLs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/\ ]+/)*index\.(php|html?)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(php|html?)$ http://www.example.com/$1 [R=301,L]
#
# Externally redirect direct client requests to remove file extensions from obsolete inbound links
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/\ ]+/)*([^.\ ]+\.)+(php|html?)\ HTTP
RewriteRule ^(([^/]+/)*[^.]+)\.(php|html?)$ http://www.example.com/$1 [R=301,L]
#
# Externally redirect testimonial and reviews URLs to append missing trailing slash
RewriteRule ^testimonials/([0-9]+)$ http://www.example.com/testimonials/$1/ [R=301,L]
RewriteRule ^reviews/(.+)$ http://www.example.com/reviews/$1/ [R=301,L]
#
# Externally redirect non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
# Internally rewrite requests for testimonials and reviews URLs to php scripts
RewriteRule ^testimonials/([0-9]+)/$ /testimonials.php?page=$1 [L]
RewriteRule ^reviews/(.+)/$ /reviews.php?page=$1 [L]
#
# Internally rewrite URLs requested with no filetype to php scripts
# unless the requested URL resolves to an existing directory or file.
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /$1.php [L]
RewriteCond %{REQUEST_URI} !^/sendmail\.php$