【问题标题】:IIS URL Rewrite URLwith Optional Index PageIIS URL 使用可选索引页面重写 URL
【发布时间】:2015-11-05 06:32:32
【问题描述】:

我已经能够对带有或不带有斜杠的 url 进行模式匹配

<match url="locations/(.+?)/?$" />

但是,我也希望能够匹配位置/[位置]/index.aspx。

如何合并此可选模式?

笨拙的我试过了:

<match url="(towns/(.+?)/?$)|(towns/(.+?)/index\.aspx$)" />

根本不喜欢!

任何帮助将不胜感激。

【问题讨论】:

  • 你问的不清楚。 .+? 匹配 index.aspx,因此添加一个替代项作为第二个不会有任何区别。
  • 对不起,我不太擅长正则表达式

标签: regex url-rewriting iis-7


【解决方案1】:

这个

(?<=locations\/)(.+?)(?=\/|$|\s)

将匹配 [location] in

/locations/[location]/
/locations/[location]
/locations/[location]/index.aspx
/locations/[location]/anything_on_the_planet.html
/locations/[location] <A bunch of text over here>

如果我能正确理解你的问题 -

  1. 带或不带斜杠
  2. 跟踪位置/
  3. 无论 [位置] 的另一边是什么都可以工作

如果你还需要什么,请告诉我

【讨论】:

    猜你喜欢
    • 2018-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    相关资源
    最近更新 更多