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

v2g6jxz6  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(63)

目前,这两个链接显示相同的页面:
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]

字符串

lnlaulya

lnlaulya1#

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

字符串

相关问题