Removing duplicate copies (html vs non-html extension)

Is there a way to redirect the first URL to the second URL?

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

Is there a way to force the .html extension to redirect to a non-html version of the URL so that it doesn't appear as duplicate copies of the same page.

Currently my htaccess code 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]

Is it possible?

0
source share
2 answers

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

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

So you can only redirect from html to non-html.

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

All Articles