避免使用.php扩展名

For example:

http://www.example.com/contact

http://www.example.com/contact.php

Not only does the first URL look cleaner, but if I decided to switch languages, it would be less of an issue.

So how does one implement this? Here is the .htaccess code I found works best:

不仅第一的网址看起来更简洁,但如果我决定切换语言,这将不再是一个问题。

那么,如何实现呢?下面是我发现最好。htaccess代码:

# If requested URL-path plus ".php" exists as a file

RewriteCond %{DOCUMENT_ROOT}/$1.php -f

# Rewrite to append ".php" to extensionless URL-path

RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]

http://www.webmasterworld.com/apache/3609508.htm