IIS URL Rewrite rule - How can I remove some segments?

自古美人都是妖i 提交于 2019-12-11 05:54:07

问题


I have read the article Creating Rewrite Rules for the URL Rewrite Module at iis.net and I would like to remove some segments from my urls.

for example, from:

/article/archive/2289/01/articleid/191/reftab/36/word1 word2 word3

to:

/article/articleid/191/word1-word2-word3

I have changed my web.config file with this but I don't be able to solve my issue:

<rewrite>
  <rules>
    <rule name="Remove segments">
      <match url="^article/archive/2289/01/([0-9]+)/([_0-9a-z-]+)" />
      <action type="Rewrite" url="article/articleid/{R:1}/{R:2}" />
    </rule>
  </rules>
</rewrite>

回答1:


It looks like you are trying to do it backwards. The <match> element represents the friendly URL - the URL the user enters in the browser, the URL contained in a link, and the URL that IIS receives.

The <action> element represents the unfriendly URL - the ugly URL that you would have to use if you weren't using the rewrite module.

<match url="^article/articleid/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="/article/archive/2289/01/articleid/{R:1}/reftab/36/{R:2}" />

The trouble here is that you probably don't want to hardcode 2289/01, right? You'll need to incorporate that into your friendly URL, or come up with some intermediary handler that can handle the request without those numbers.



来源:https://stackoverflow.com/questions/10268275/iis-url-rewrite-rule-how-can-i-remove-some-segments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!