问题
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