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

问题描述 投票:0回答:2

目前,这两个链接显示同一页面:

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 .htaccess file-extension
2个回答
23
投票
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

0
投票

如何移动网站的一部分(例如文件夹),而不是全部更改: (原创)https://my-site.com/catalog/subcat/this-is-first-post.html (至......)https://my-site.com/catalog/subcat/this-is-first-post/

使用“/”会更短更好。谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.