虽然有人可能质疑这种事情的用处,但这是可行的,所以这里是如何使用mod_rewrite在.htaccess中完成的:
RewriteEngine On
# Sets your index script
RewriteRule ^$index.php [L]
# Condition prevents redirect loops (when script is not found)
RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteCond %{REQUEST_FILENAME} !-f
# Stop here if the file is not found after a redirect
RewriteRule ^(.*)$notfound.php [L]
# Condition prevents redirect loops (when script is found)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Forbid access directly to PHP files
RewriteRule ^.*?\.php$forbidden [F,L]
# Make sure the filename does not actually exist (images, etc.)
RewriteCond %{REQUEST_FILENAME} !-f
# Append the .php extension to the URI
RewriteRule ^(.*)$$1.php [L]