使用URL重写进行跨域Http请求 [英] Using URL Rewrite for Cross-Domain Http Requests

查看:1003
本文介绍了使用URL重写进行跨域Http请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个入站重写规则,该规则基本上捕获对根文件夹/ api / *的所有请求,并将其重写为api.v2.movi​​deo.com,尊重HTTP与HTTPS流量。

I am trying to write an inbound rewrite rule that basically captures all the requests to the root folder /api/*, and rewrite it to api.v2.movideo.com respecting the HTTP vs HTTPS traffic.

我按照这里的分步说明进行操作: http://code.movi​​deo.com/Setting_up_IIS7_to_use_URL_Rewrite_2.0_for_Cross-Domain_XMLHttpRequest_Calls

I followed the step by step instructions here: http://code.movideo.com/Setting_up_IIS7_to_use_URL_Rewrite_2.0_for_Cross-Domain_XMLHttpRequest_Calls

我安装了应用程序请求路由 http://www.iis.net/expand/URLRewrite
按照该页面上的所有步骤,删除指示的标题,书中的所有内容,但我得到的只是:

I installed Application Request Routing http://www.iis.net/expand/URLRewrite Followed all the steps on that page, removed the instructed headers, did everything by the book, but all I get is this:

HTTP错误500.50 - URL重写模块错误。
您正在寻找的资源存在问题,因此无法显示。

HTTP Error 500.50 - URL Rewrite Module Error. There is a problem with the resource you are looking for, so it cannot be displayed.

当我将规则从REWRITE更改为REDIRECT时,它运行正常,但它重定向,而不是重写!啊。这里发生了什么?

When I change the rule from REWRITE to REDIRECT, it works fine, but it redirects, not rewrites! Ugh. What's going on here?

这是我的规则:

            <rule name="ReverseProxyInboundRule1" stopProcessing="false">
                <match url="^api/(.*)" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{CACHE_URL}" pattern="^(https?)://" />
                </conditions>
                <action type="Rewrite" url="{C:1}://api.movideo.com/{R:1}" />
                <serverVariables>
                    <set name="HTTP_ACCEPT_ENCODING" value="" />
                </serverVariables>
            </rule>

(第二个问题:我是否应该知道安装应用程序请求路由有什么问题或事情?它添加了一个我的IIS中的新服务器农场部分,嗯...我不知道这是什么。)

(2nd question: Are there any problems or things I should know installing Application Request Routing? It added a new 'Server Farms' section in my IIS, hmmmm...I have no idea what this is all about. )

推荐答案


  1. 如果在此规则之后有处理规则,请考虑将 stopProcessing 属性设置为true

  2. 因为您使用的是 serverVariables 节点,您必须将服务器变量添加到服务器的allowedServerVariables集合中。您可以使用IIS UI执行此操作(此处详细信息:设置HTTP请求标头和IIS服务器变量)或从命令行:

  1. If there are processing rules AFTER this rule, consider setting the stopProcessing attribute to true
  2. Because you are using a serverVariables node, you must add the server variable to the allowedServerVariables collection for your server. Your can do this from using the IIS UI (details here: Setting HTTP request headers and IIS server variables) or from the command line:

%windir%\ System32 \inetsrv\appcmd.exe set config -section:system.webServer / rewrite / allowedServerVariables / +[name ='boo']/ commit:apphost

%windir%\System32\inetsrv\appcmd.exe set config -section:system.webServer/rewrite/allowedServerVariables /+"[name='boo']" /commit:apphost

这篇关于使用URL重写进行跨域Http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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