2016-11-07 100 views
0

我目前的网址是:mysite.com/datasheet/100-DE-xmas2016-6网址重写 “ - ” 符号划分参数

在web.config中:

<rule name="myrule"> 
    <match url="^datasheet/([_0-9a-z-]+)-([_0-9a-z-]+)-([_0-9a-z-]+)" /> 
    <action type="Rewrite" url="ajax/datasheet.aspx?shop={R:1}&amp;language={R:2}&amp;product={R:3}" /> 
</rule> 

会不重写

mysite.com/ajax/datasheet.aspx?shop_id=100 &语言= DE &产品= xmas2016-6

为什么? 如何使产品“xmas2016-6”可以工作? 列表“mysite.com/datasheet/100-DE-xmas20166”将起作用。但我真的很想用产品作为“xmas2016-6”(在正则表达式中设置为[_0-9a-z-],但它像忽略产品参数中的“ - ”符号或什么?)

回答

0

此规则会为你工作:

<rule name="myrule"> 
    <match url="^datasheet/([_0-9a-z]+)\-([_0-9A-Z]+)\-([_a-z]+[0-9]{4})([0-9]{1})$" /> 
    <action type="Rewrite" url="/ajax/datasheet.aspx?shop={R:1}&amp;language={R:2}&amp;product={R:3}-{R:4}" /> 
</rule> 

正则表达式^datasheet/([_0-9a-z]+)\-([_0-9A-Z]+)\-([_a-z]+[0-9]{4})([0-9]{1})$被分裂datasheet/100-DE-xmas20166分为四组:

  • {R:0} datasheet/100-DE-xmas20166
  • {R:1} 100
  • {R:2} DE
  • {R:3} xmas2016
  • {R:4} 6