IIS 重写不起作用(但重定向可以) [英] IIS Rewrite not working (but redirection does)

查看:71
本文介绍了IIS 重写不起作用(但重定向可以)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试使用 Rewrite Module 2.0 进行 URL 重写,但我没有成功让它工作.我想要做的是将端口 80 对 Web 应用程序的所有调用重新写入 IIS 中托管的其他应用程序(或者可能位于网络上的不同服务器上).使用 IIS 提供的 GUI,我创建了以下规则:

I was trying to play with URL re-writing using the Rewrite Module 2.0 but I had no luck getting it to work. What I'm trying to do is re-write all calls to web app at port 80 to other applications hosted in IIS (or maybe on different servers on the network). Using the GUI provided by IIS I created the following rule:

<rewrite>
    <rules>
        <rule name="ReverseProxyInboundRule1" stopProcessing="true">
            <match url="site1/(.*)" />
            <action type="Rewrite" url="http://localhost:7001/{R:1}" />
        </rule>
    </rules>
</rewrite>

安静简单,可惜行不通.另一方面,当我将操作类型更改为 Redirect 时,它工作正常.

Quiet simple, but unfortunately it does not work. On the other hand, when I change the action type to Redirect, it works fine.

可能是什么问题?

推荐答案

我昨天遇到了同样的问题,我花了很长时间才弄明白.

I ran into this same issue yesterday, and it took me a long time to figure out.

这里的关键是您在重写操作中有一个 http:// 前缀;这使得这是一个需要由应用程序请求路由处理的特殊情况.第一步是确保安装了应用程序请求路由模块.您可以在 https://www.iis.net/downloads/microsoft/application-request-路由.安装完成后,转到您的 IIS Web 服务器(从您的网站开始),然后打开应用程序请求路由缓存功能.从右侧的操作中,选择 Server.Proxy.Settings,并确保选中启用代理"复选框.这允许将 URL 重写任务重新路由到应用程序请求路由,并且您的反向代理应该可以用于外部请求.

The key here is that you've got an http:// prefix in your rewrite action; that makes this a special case that needs to be handled by Application Request Routing. The first step is to make sure that the Application Request Routing module is installed. You can find the module at https://www.iis.net/downloads/microsoft/application-request-routing. Once that is installed, go to your IIS web server (a level up from your web site), and open the Application Request Routing Cache feature. From the actions on the right, choose Server.Proxy.Settings, and make sure that the "Enable Proxy" checkbox is checked. This allows the URL rewrite task to be re-routed to Application Request Routing, and your reverse proxy should work for external requests.

这个想法来自 2009 年的这篇优秀博客文章:http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/

The idea came from this excellent blog post from 2009: http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/

这篇关于IIS 重写不起作用(但重定向可以)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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