关于IIS 伪静态 URL重写的正则匹配问题.

devmsg 2019-01-27 12:12:46
服务器环境, windows 2012, urlrewrite2, web.config

URL:
1). articles-a12345.html
2). articles-v12345.html
3). articles-a1234567.html
4). articles-v1234567.html

如果正则是:

articles\-(\w+)\.html$

即:
......
<rule name="articles">
<match url="articles\-(\w+)\.html$" />
<action type="Rewrite" url="/view/?id={R:1}" />
</rule>
...

则 1) 2) 3) 4) 全部匹配了,

如果我只想匹配 1) 和 2),正则如何来写啊? 也就是长度为 6 ( "a12345" 是六个字符 )

如果我想匹配 长度为 6到9 ( "axxxxxx " 长度为 6,7,8,9 ) 又该如何写啊?

...全文
297 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hzy694358 2019-04-11
  • 打赏
  • 举报
回复
<match url="articles\-(\w{6})\.html$" /> //6个字符

8,327

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 IIS
社区管理员
  • IIS
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧