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

时间:2012-07-02 20:54:56

标签: html .htaccess redirect

有没有办法让第一个网址重定向到第二个网址?

http://www.example.com/podcast/episode.html
http://www.example.com/podcast/episode

有没有办法强制.html扩展名重定向到网址的非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]

这可能吗?

2 个答案:

答案 0 :(得分:0)

不完全确定我是否理解这个问题,但是如果你想要以.html结尾的任何内容重定向到没有.html的同一个网址,那么这应该可以解决问题:

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

答案 1 :(得分:0)

这就是你如何只能从html重定向到非html。

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