如何使用htaccess重定向html扩展名?

8
目前,这两个链接显示的是同一个页面: http://www.example.com/podcast/episode.html
http://www.example.com/podcast/episode 我想要做的是将所有html类型的链接重定向到非html链接。
我知道使用htaccess可能很简单,但对我来说不起作用。
以下是我的htaccess代码:
    RewriteEngine On
    RewriteBase /

    #removing trailing slash

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ $1 [R=301,L]

    #non www to www

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

    #shtml

    AddType text/html .html
    AddHandler server-parsed .html

    #html

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^\.]+)$ $1.html [NC,L]

    #index redirect

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/ 
    RewriteRule ^index\.html$ http://example.com/ [R=301,L]

可能是[删除重复副本(html扩展名与非html)]的重复问题(http://stackoverflow.com/questions/11301039/removing-duplicate-copies-html-extension-vs-non-html) - Jon Lin
1个回答

23
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

1
完美地工作了。谢谢Gerben。 - Jeremy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接