【问题标题】:How to redirect *.htm *,htm *,html to *.html in .htaccess如何将 *.htm *,htm *,html 重定向到 .htaccess 中的 *.html
【发布时间】:2021-08-30 19:56:54
【问题描述】:

我需要将*.htm *,htm *,html 重定向到*.html,但当页面为*.html 时,请保留相同的网址*.html

我有这个规则,但是有问题 -> 重定向循环。我应该改变什么?

RewriteEngine On
RewriteRule ^(.*)(\.|,)htm(l?)$ $1.html [R=301]

【问题讨论】:

  • 你的模式匹配.html,所以它会再次重定向。您需要分别处理*.htm*,htm*,html。类似^(.*)(\.htm|,html?)$

标签: regex apache .htaccess mod-rewrite


【解决方案1】:

正如 CBroe 正确评论的那样,问题在于您的模式也与 .html 匹配,因此将导致重定向循环。

您可以使用以下方法修复它:

RewriteRule ^(.+)(?:\.htm|,html?)$ $1.html [R=301,L,NC,NE]

PS:这里假设 RewriteBase 指令之前已经使用过。

【讨论】:

    猜你喜欢
    • 2013-09-08
    • 1970-01-01
    • 2023-03-29
    • 2013-04-15
    • 2011-06-04
    • 1970-01-01
    • 2016-06-05
    • 1970-01-01
    • 2019-05-12
    相关资源
    最近更新 更多