1

我正在尝试mod-rewrite摆脱.htaccess“.php”文件扩展名。

所以基本上,这是我现在的网站:http ://www.example.com/about.php

这是我想要的:http ://www.example.com/about

有没有办法在我的 .htaccess 中使用mod-rewrite?非常感谢!

4

1 回答 1

2

我想到了!如果您希望它适用于“.html”扩展名,您应该将“.php”更改为“.html”

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

带有 !-d 的行检查它不是一个目录,带有 -f 的行检查请求的文件是一个 .php 文件。

但是,要显示它,您需要像这样链接到它:

<a href="http://www.example.com/about"></a>

代替:

<a href="http://www.example.com/about.php"></a>

因为那样它只会将 URL 显示为 about.php。

希望这有助于任何想要这样做的人!

于 2012-08-30T19:27:14.010 回答