【问题标题】:rewrite any combination of index.html重写 index.html 的任意组合
【发布时间】:2017-10-09 00:24:41
【问题描述】:

我对将 index.html 的任何字母大小写组合的 URL 重定向到 index.html 的所有小写字母感兴趣。

即:

/foo/bar/INDEX.html
to 
/foo/bar/index.html

or

/hello/world/funk/indeX.HTML
to 
/hello/word/fund/index.html

我尝试了几个正则表达式,但没有运气。仅当index.html 中有任何大写字母时,我才对重定向感兴趣

/hello/there/index.html 不应重定向到任何地方。

我可以访问 httpd.conf,因此我使用的是RewriteMap lc int:tolower

【问题讨论】:

  • 可能最简单/最直接的正则表达式是^(.*)[iI][nN][dD][eE][xX]\.[hH][tT][mM][lL]$。但是,它不满足仅重写并且仅在至少有 1 个大写字母时才重写的要求。它也会匹配小写的index.html。但我不明白为什么会有问题。

标签: regex apache http url url-rewriting


【解决方案1】:

试试这个:(?!index\.html)(?i)index\.html(?-i) 它首先检查字符串是否不是index.html,然后匹配任何不区分大小写的字符串index.html。在这里试试:https://regex101.com/r/GNhAwG/1

【讨论】:

    猜你喜欢
    • 2021-07-29
    • 2018-02-06
    • 2013-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2013-02-10
    相关资源
    最近更新 更多