IIS URL重写规则 - 如何删除某些段? [英] IIS URL Rewrite rule - How can I remove some segments?

查看:336
本文介绍了IIS URL重写规则 - 如何删除某些段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读文章在iis.net上创建URL重写模块的重写规则,我想从我的网址中删除一些段。

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.

例如,来自:

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

to:

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

我已用此更改了我的web.config文件但我无法解决我的问题:

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>


推荐答案

看起来你正试图倒退。 < match> 元素表示友好的URL - 用户在浏览器中输入的URL,链接中包含的URL以及IIS接收的URL。

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.

< action> 元素代表不友好的网址 - 您将拥有的丑陋网址如果您没有使用重写模块,请使用。

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}" />

这里的麻烦是你可能不想硬编码 2289 / 01 ,对吗?您需要将其合并到友好的URL中,或者提供一些可以处理请求的中间处理程序,而不需要这些数字。

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.

这篇关于IIS URL重写规则 - 如何删除某些段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆