Htaccess - 删除扩展名

时间:2012-02-09 11:41:58

标签: .htaccess redirect

如果网址中缺少 http:// www ,我会添加 http:// www 。如果重定向发生,.html扩展名由于某种原因而被添加:

  

example.com/about> htaccess> http://www.example.com/about.html

为什么添加 .html ? 这是我的htaccess:

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

我想拥有没有 .html 部分的链接:

  

example.com/about> htaccess> http://www.example.com/about

感谢。 乌利

1 个答案:

答案 0 :(得分:0)

这样做:

Rewritecond %{REQUEST_URI} !-f
Rewritecond %{REQUEST_URI} !-d
Rewritecond %{REQUEST_URI} !-l
RewriteRule ^([\w\d\-]+)$ $1.html [L] 

我建议您在http://www.example.com/whatever中使用http://www.example.com/whatever.html代替h refs