2012-07-04 37 views
5

Tại thời điểm này, cả hai liên kết hiển thị cùng một trang:Làm thế nào để chuyển hướng phần mở rộng html bằng cách sử dụng htaccess?

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

Những gì tôi muốn làm là chuyển hướng tất cả các liên kết html-type cho các liên kết không html.

Tôi biết điều này có vẻ đơn giản để làm với htaccess, nhưng nó không làm việc cho tôi.

Dưới đây là code htaccess của tôi cho đến nay:

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] 
+0

thể trùng lặp của [Loại bỏ các bản sao trùng lặp (mở rộng html vs phi html)] (http://stackoverflow.com/questions/11301039/removing -duplicate-copy-html-extension-vs-non-html) –

Trả lời

9
RewriteCond %{THE_REQUEST} \.html 
RewriteRule ^(.*)\.html$ /$1 [R=301,L] 
+1

Làm việc hoàn hảo. Cảm ơn Gerben. – Jeremy

Các vấn đề liên quan