如何添加URL后缀

时间:2009-11-13 05:59:41

标签: php apache .htaccess httpd.conf

我只是想问一下如何使用htaccess将html后缀添加到我网站的每个网址?

这样的网址:

www.mysite.com/index.php?hello/world

应该成为

www.mysite.com/index.php?hello/world.html

2 个答案:

答案 0 :(得分:2)

  RewriteEngine On

  RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]

  RewriteRule ^(.*)$ http://www.mydomain.com/$1\.html [R=301,L] 

答案 1 :(得分:1)

另一种方法是启用 MultiViews 。只需将以下行添加到目录(或httpd.conf)中的.htaccess文件即可。请注意,Options All无法启用MultiView,您需要明确启用它。

Options +MultiViews

有关选项的更多信息,请参阅http://httpd.apache.org/docs/2.0/en/content-negotiation.html中的“多视图”部分,有关选项的更多信息,请参阅http://httpd.apache.org/docs/2.0/en/mod/core.html#options