【问题标题】:How to redirect html extension using htaccess?如何使用 htaccess 重定向 html 扩展?
【发布时间】:2012-07-04 11:49:03
【问题描述】:

目前,这两个链接都显示相同的页面:

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

我想要做的是将所有 html 类型的链接重定向到非 html 链接。

我知道这对 htaccess 来说似乎很简单,但它不适合我。

到目前为止,这是我的 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 .htaccess file-extension


【解决方案1】:
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

【讨论】:

  • 完美运行。谢谢格本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-10
  • 2021-09-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多