【问题标题】:Regex help needed!需要正则表达式帮助!
【发布时间】:2023-03-19 13:12:01
【问题描述】:

我正在开发一个使用基于 IIS7 的 url 重写的多语言应用程序。

我想要以下 Url 操作:

1. fr-ca > index.aspx?l=&lc=fr-ca
2. fr-ca/ > index.aspx?l=&lc=fr-ca
3. fr-ca/568/sometitle > index.aspx?l=568&lc=fr-ca
4. 568/sometitle > > index.aspx?l=568&lc=

本质上,最初的 fr-ca 是可选的。

我目前的规则:

<match url="^(fr-ca.)?([^/][0-9]+)?/*" />

#1 失败

另一个尝试:

<match url="^(fr-ca)?(.[0-9]+)?/*" />

通过所有要求,除了反向引用 {R:2} 在这种情况下给出 /568。

我想我可以添加另一个规则,只在 fr-ca 的末尾添加 /,但这似乎不正确。

感谢您的帮助!正则表达式让我发疯。

【问题讨论】:

    标签: regex iis-7 url-rewriting


    【解决方案1】:

    你应该这样做吗?您实际上可以检查 Accept-Language 标头...甚至可能从该 ASP 页面中查看,而不是查看他们点击了哪个 url(并重定向到我认为是该页面的翻译版本)。

    这意味着他们从一开始就可以看到他们想要看到的语言,而无需点击页面顶部那个愚蠢的小标志。它不依赖 GeoIP 或用户交互。

    检查一下。

    【讨论】:

    • 你对我的问题有答案了吗?
    【解决方案2】:

    我自己整理的。

    ^(fr-ca)?/?([0-9]+)?
    

    通过:

    fr-ca
    fr-ca/
    fr-ca/9
    fr-ca/9/
    fr-ca/9/sometitle
    fr-ca/9/sometitle/
    fr-ca/9/sometitle/anothertitle
    
    9
    9/
    9/sometitle
    9/sometitle/
    9/sometitle/anothertitle
    

    【讨论】:

      猜你喜欢
      • 2012-11-30
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-01
      • 2016-02-01
      相关资源
      最近更新 更多