删除重复副本(html扩展与非html)

删除重复副本(html扩展与非html),html,.htaccess,redirect,Html,.htaccess,Redirect,有没有办法将第一个URL重定向到第二个URL 有没有办法强制.html扩展重定向到URL的非html版本,这样就不会显示为同一页面的重复副本 我目前的htaccess代码是: RewriteEngine On RewriteBase / #removing trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ $1 [R=301,L] #non www

有没有办法将第一个URL重定向到第二个URL


有没有办法强制.html扩展重定向到URL的非html版本,这样就不会显示为同一页面的重复副本

我目前的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结尾的内容重定向到相同的URL,而不使用.html,那么应该这样做:

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

这就是您如何仅从html重定向到非html的方法

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ (/[^\ ]+)\.html\  [NC]
RewriteRule ^ %1 [L,R=301]

我试过了,它重定向到[我忘了它前面的^,请再试一次!不幸的是仍然无法工作。事实上,发生了一些事情,现在pavlinaplus.com/podcast/growth重定向到pavlinaplus.com/growth。(pavlinaplus.com/podcast/growth.html仍然有效)终于找到了答案:.htaccess文件是在您的文档根目录中还是在您的播客目录中?这是一个非常非常重要的细节。@JonLin.htaccess文件在文档根目录中。不知道出了什么问题,我将您的规则和Tim Stoop的规则粘贴到测试apache服务器中,它们工作正常。@JonLin您是否将Tim的规则添加到了htacc的顶部还是…在哪里?@JonLin只是想让你知道,终于找到了答案: