Forum Moderators: phranque
ErrorDocument 404 / ErrorDocument 404 http://www.example.com ErrorDocument 404 /page.html ErrorDocument 404 /error ErrorDocument 404 /404error.html
# If requested filepath exists when ".php" is appended to it
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js|php)$
ErrorDocument 404 /404error.html
ErrorDocument 500 /500error.html
#
Options +FollowSymLinks -MultiViews
RewriteEngine on
#
# Skip all of the following rules to allow serving
# critical custom error documents to all requestors
RewriteRule ^(403|500)error\.html$ - [L]
#
# Disallow hotlinking
RewriteCond %{HTTP_REFERER} !^(http://www\.example\.com.*)?$
RewriteRule \.(gif|jpe?g|png|bmp|css|js)$ - [F]
#
# Externally redirect to remove ".php" from direct client requests
RewriteCond %{THE_REQUEST} ^GET\ /([^/]+/)*[^.]+\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php$ http://www.example.com/$1 [R=301,L]
#
# Externally redirect to remove double (or multiple) slashes in requested URL-path
RewriteCond %{REQUEST_URI} ^(.*)//+(.*)$
RewriteRule / http://www.example.com/%1/%2 [R=301,L]
#
# Externally redirect to remove trailing slash if the requested
# URL-path does not resolve to an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://www.example.com/$1 [R=301,L]
#
# Externally redirect non-blank non-canonical hostname requests to
# canonical domain (if not already done by one of the preceding rules)
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
# Internally rewrite requests for URLs which do not resolve
# to physically-existing files or directories to a PHP file
# (Note that images, other included objects, and php scripts
# are excluded to avoid excessive -exists checking)
RewriteCond $1 !\.(gif|jpe?g|png|bmp|ico|css|js|php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ /$1.php [L]