【问题标题】:Remove .html from URL + redirect [duplicate]从 URL + 重定向中删除 .html [重复]
【发布时间】:2017-05-22 11:55:27
【问题描述】:

我想从 URL 中显示的 URL 中删除 .html 部分。

我能够解决这个问题:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f

这行得通! :)

但现在我得到了每个页面的双 URL

  • 第1页
  • page1.html

我不希望 .html 页面上出现 404 错误,因此我想将其重定向到没有 .html 的页面(301 重定向)。但我不知道在 .htaccess 中这样做

我试过了:

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

但不起作用 --> .html 文件仍然有效

有谁能帮帮我吗? :) 谢谢!

ps。我真的不会写.htaccess,请回答我可以复制粘贴。太多了!

【问题讨论】:

标签: html .htaccess redirect


【解决方案1】:

试试这个

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^([^\.]+)$ $1.html [NC,L]

ErrorDocument 404 /404 

【讨论】:

    猜你喜欢
    • 2011-12-03
    • 2012-05-01
    • 1970-01-01
    • 2014-09-26
    • 2021-05-10
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多