删除重复的副本(HTML扩展VS非HTML)副本、HTML、VS

2023-09-02 01:08:45 作者:好命靠努力

有没有什么办法让第一个URL重定向到第二个URL?

Is there any way to have the first URL redirect to the second URL?

http://www.example.com/podcast/episode.html < BR> http://www.example.com/podcast/episode

有没有办法强制.html扩展重定向到URL的非HTML版本,以免显示为同一页的重复副本。

Is there any way to force the .html extension to redirect to the non-html version of the URL, so as not to show up as duplicate copies of the same page.

我的htaccess code,此刻是:

My htaccess code at the moment is:

    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结尾重定向到相同的URL没有html的,这应该做的绝招:

Not entirely sure if I understand the question, but if you want anything ending in .html to redirect to the same URL without the .html, this should do the trick:

RewriteRule ^/(.*).html$ /$1 [R=301,L]