【问题标题】:Tuckey Rewrite: Removing ExtensionTuckey 重写:删除扩展
【发布时间】:2014-03-26 18:17:38
【问题描述】:

我正在使用 Tuckey 删除带有以下规则的 URL .xhtml 扩展名:

<rule>
    <from>^/?([a-z-]+)/$</from>
    <to>/$1.xhtml</to>
</rule>

<rule>
    <from>^/?([a-z-]+)$</from>
    <to>/$1.xhtml</to>
</rule>

所以 /page/ 和 /page 被映射到 /page.xthml

但是,如果我有 /directory/page/ 这不会映射到 /directory/page.xhtml。

【问题讨论】:

    标签: regex rewrite tuckey-urlrewrite-filter


    【解决方案1】:
    <rule>
        <from>^/?([a-z-/]+)/$</from>
        <to>/$1.xhtml</to>
    </rule>
    
    <rule>
        <from>^/?([a-z-/]+)$</from>
        <to>/$1.xhtml</to>
    </rule>
    

    我将斜杠添加到可重复字符列表中,这很有效

    【讨论】:

      【解决方案2】:

      使用这条规则:

      <rule>
          <from>^/?[a-z-]*?/?([a-z-]+)/$</from>
          <to>/$1.xhtml</to>
      </rule>
      
      <rule>
          <from>^/?[a-z-]*?/?([a-z-]+)$</from>
          <to>/$1.xhtml</to>
      </rule>
      

      【讨论】:

      • 为什么这比我已经发布的答案更好?如果 url 是 /directory/directory/page 怎么办?
      • 我知道它会允许零次或多次,你的将允许零次或一次,让 OP 决定什么适合他:)
      猜你喜欢
      • 2012-02-24
      • 2015-03-14
      • 2022-03-04
      • 1970-01-01
      • 1970-01-01
      • 2014-12-22
      • 2019-04-21
      • 2012-11-02
      • 1970-01-01
      相关资源
      最近更新 更多