使用.htaccess和mod_rewrite在php页面中不需要文件扩展名


Using .htaccess and mod_rewrite to not require file extensions in php pages

希望能给大家一个快速的URL重写问题。

我有一个网页在我的网站:http://www.sample.com/whatever.php

和我想能够导航的网站,而不键入.php

所以http://www.sample.com/whatever会显示同样的东西

我希望这对根目录下的任何文件都有效,所以用户可以使用或不使用扩展名。

任何想法吗?

根据上面的评论,我使用Apache的MultiViews解决了这个问题

将下面的代码添加到我的。htaccess文件中就成功了:

Options +MultiViews
AddType application/x-httpd-php .php

更新:更多细节在这里:http://www.bmt-online.org/geekisms/php-multiviews

我想这应该可以了

htcaccess:

RewriteEngine on
RewriteBase /
RewriteRule whatever$ whatever.php