【问题标题】:write a redirect rule in web.config in asp.net application在 asp.net 应用程序的 web.config 中编写重定向规则
【发布时间】:2016-08-25 12:39:53
【问题描述】:

我在一个网站上有一个帮助部分,现在我希望它重定向到另一个地方。网站的其余部分应该保持不变,这意味着只有帮助部分/内容应该让用户转到另一个网站:

device.domain.net/collection/hgkhghj 应该返回到 device.domain.net/collection

我可以在 hgkhghj 的地方拥有任何东西。如果我正在写 device.domain.net/collection 那么它应该返回 device.domain.net/collection

 <rule name="Help Redirect" stopProcessing="true">            
            <match url="(.*)/collection(.*)" ignoreCase="true" />
            <action type="Redirect" url="http:/device.domain.net" appendQueryString="false" redirectType="Permanent" />
          </rule>

但目前它正在返回到 device.domain.net。

我想再制定一条规则,如果我输入 device.domain.net/gcfhgg 那么它应该返回到 device.domain.net。

<rule name="Help Redirect" stopProcessing="true">            
        <match url="(.*)" ignoreCase="true" />
        <action type="Redirect" url="http://device.domain.net" appendQueryString="false" redirectType="Permanent" />
      </rule>

但它不起作用。

【问题讨论】:

    标签: c# asp.net iis web-config


    【解决方案1】:

    对于您的第一条规则,您可以使用以下内容(假设它在同一个域上):

    <rule name="Help Redirect" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="^collection/(.*)" />
      <action type="Redirect" url="collection" appendQueryString="false" redirectType="Permanent" />
    </rule>
    

    如果这是在另一个域上,您还需要安装 ARR。您的第二条规则更复杂,因为它看起来好像您仅在您点击 404 页面时才尝试执行重定向。这是我使用重写规则从未做过的事情。是否有理由这样做而不是显示自定义 404 页面?

    【讨论】:

    • 这条规则不起作用。它给出了错误 device.domain.net redirect you too many times.
    • 抱歉@Nikhil 重定向发生时操作 url 被捕获。最重要的规则现在需要一个集合 / 并重定向到不带斜线的集合。我已经更新了答案。应该做的工作
    • 是的,它正在工作,但如果我为 device.domain.net/collection/news 制定相同的规则并制定像 然后是不工作。我应该在浏览器中看到 url 为 device.domain.net/collection/news-update 但它没有工作并给出错误
    • 所以你有答案中提到的规则,你要在前面提到的规则之上添加一个新规则?
    猜你喜欢
    • 2019-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-26
    • 2020-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多