webconfig中匹配正则 急急急

DiscussQuestions 2011-09-20 10:00:31
在用urlrewrite.dll做伪静态的时候出现一个问题
就是红色部分是用 wap或者3g都可以,但是正则不知道怎么写
急急急,在线等待

<RewriterRule>
<LookFor>~/(wap|3g)/index.html</LookFor>
<SendTo>~/(wap|3g)/index.aspx</SendTo>
</RewriterRule>
...全文
150 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
DiscussQuestions 2011-09-22
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 huangwenquan123 的回复:]

引用 9 楼 discussquestions 的回复:
引用 8 楼 sxldfang 的回复:

引用 5 楼 discussquestions 的回复:

引用 4 楼 sxldfang 的回复:

$1就代表了找到的正则()中的内容,可能是wap,也可能是3g

比如,网址是 ~/wap/index.html,就转移到~/wap/index.aspx
若是~/3g/i……
[/Quote]

这个还是不可以
以上配置报错信息:
访问之后报错 “http://test.123.com/click”不是有效的虚拟路径。
huangwenquan123 2011-09-21
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 discussquestions 的回复:]
引用 8 楼 sxldfang 的回复:

引用 5 楼 discussquestions 的回复:

引用 4 楼 sxldfang 的回复:

$1就代表了找到的正则()中的内容,可能是wap,也可能是3g

比如,网址是 ~/wap/index.html,就转移到~/wap/index.aspx
若是~/3g/index.html,则转移到~/3g/index.aspx
……
[/Quote]
test
<RewriterRule>
<LookFor>~/(wap|3g|iphone|qq)/read/(\d+)/(\d+)_0_0\.html</LookFor>
<SendTo><![CDATA[http://test.123.com/click?id=$1&u=http://test.com:80/read.aspx?aid=$2&bid=$3]]></SendTo>
</RewriterRule>
半瓶神仙水 2011-09-21
  • 打赏
  • 举报
回复
友情UP
DiscussQuestions 2011-09-21
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 sxldfang 的回复:]

引用 5 楼 discussquestions 的回复:

引用 4 楼 sxldfang 的回复:

$1就代表了找到的正则()中的内容,可能是wap,也可能是3g

比如,网址是 ~/wap/index.html,就转移到~/wap/index.aspx
若是~/3g/index.html,则转移到~/3g/index.aspx


如果我又两个参数,
<Rewrite……
[/Quote]

如帖子:
http://topic.csdn.net/u/20110921/14/3f730112-de0d-4d01-8d04-732bee16acd0.html
DiscussQuestions 2011-09-21
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 sxldfang 的回复:]

引用 5 楼 discussquestions 的回复:

引用 4 楼 sxldfang 的回复:

$1就代表了找到的正则()中的内容,可能是wap,也可能是3g

比如,网址是 ~/wap/index.html,就转移到~/wap/index.aspx
若是~/3g/index.html,则转移到~/3g/index.aspx


如果我又两个参数,
<Rewrite……
[/Quote]

但是还有一种情况不行,如下:

<RewriterRule>
<LookFor>~/(wap|3g|iphone|qq)/read/(.\d*)/(.\d*)_0_0\.html</LookFor>
<SendTo><![CDATA[http://test.123.com/click?id=$1&u=http://test.com:80/read.aspx?aid=$2&bid=$3]]></SendTo>
</RewriterRule>


  • 打赏
  • 举报
回复
[Quote=引用 5 楼 discussquestions 的回复:]
引用 4 楼 sxldfang 的回复:

$1就代表了找到的正则()中的内容,可能是wap,也可能是3g

比如,网址是 ~/wap/index.html,就转移到~/wap/index.aspx
若是~/3g/index.html,则转移到~/3g/index.aspx


如果我又两个参数,
<RewriterRule>
<LookFor>~/(wap|3g)/ind……
[/Quote]

按照正则中从左到右的()分级的,$1表示第一组中匹配到的内容,只要上下对应就好了
sunhuaiwei 2011-09-20
  • 打赏
  • 举报
回复
一般不调换,调换你可以试一下可以不?要确定对应的数据类型正确。
DiscussQuestions 2011-09-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 sxldfang 的回复:]

$1就代表了找到的正则()中的内容,可能是wap,也可能是3g

比如,网址是 ~/wap/index.html,就转移到~/wap/index.aspx
若是~/3g/index.html,则转移到~/3g/index.aspx
[/Quote]

如果我又两个参数,
<RewriterRule>
<LookFor>~/(wap|3g)/index_(.\d*).html</LookFor>
<SendTo>~/$1/index.aspx?id=$2</SendTo>
</RewriterRule>

$1和$2可以调换位置吗
sxldfang 2011-09-20
  • 打赏
  • 举报
回复
$1就代表了找到的正则()中的内容,可能是wap,也可能是3g

比如,网址是 ~/wap/index.html,就转移到~/wap/index.aspx
若是~/3g/index.html,则转移到~/3g/index.aspx
sxldfang 2011-09-20
  • 打赏
  • 举报
回复
<RewriterRule>
<LookFor>~/(wap|3g)/index.html</LookFor>
<SendTo>~/$1/index.aspx</SendTo>
</RewriterRule>
masterkong123 2011-09-20
  • 打赏
  • 举报
回复
轻轻巧巧
DiscussQuestions 2011-09-20
  • 打赏
  • 举报
回复
[Quote=引用楼主 discussquestions 的回复:]
在用urlrewrite.dll做伪静态的时候出现一个问题
就是红色部分是用 wap或者3g都可以,但是正则不知道怎么写
急急急,在线等待
红色不管用了,不好意思
<RewriterRule>
<LookFor>~/(wap|3g)/index.html</LookFor>
<SendTo>~/(wap|3g)/index.aspx</SendTo>
</RewriterRule>
[/Quote]
sxldfang 2011-09-20
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 discussquestions 的回复:]

引用 4 楼 sxldfang 的回复:

$1就代表了找到的正则()中的内容,可能是wap,也可能是3g

比如,网址是 ~/wap/index.html,就转移到~/wap/index.aspx
若是~/3g/index.html,则转移到~/3g/index.aspx


如果我又两个参数,
<RewriterRule>
<LookFor>~/(wap|3g)/in……
[/Quote]

下面的写法也没问题
<RewriterRule>
<LookFor>~/(wap|3g)/index_(.\d+).html</LookFor>
<SendTo>~/$2/index.aspx?id=$1</SendTo>
</RewriterRule>

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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