我正在尝试使用 ARR 和 URL 重写进行反向代理以实现以下重定向:
显示的最终 URL 将与源 URL 相同。
重定向工作正常,但是在外部浏览时,我所有的 JavaScript 文件都被转换为 content-type text/html
而不是 application/javascript
。这会导致出现空白页面而不是实际功能。
重写规则:
<rules>
...
<rule name="ReverseProxyInboundRule2" stopProcessing="true">
<match url="^test(.*)" />
<action type="Rewrite" url="http://{HTTP_HOST}:83/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="IsJavascript">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" customTags="" pattern="^http(s)?://localhost:83/(.*)" />
<action type="Rewrite" value="http{R:1}:{HTTP_HOST}/{R:2}" />
</rule>
<preConditions>
<preCondition name="IsJavascript">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^application/javascript" />
</preCondition>
</preConditions>
</outboundRules>
目标页面使用 AJAX 功能,由于 js 文件被随机 html 标记损坏,导致 AJAX 功能失败。我该如何纠正这个问题?
最佳答案
最终确定问题是由于目标应用程序中的相对路径引起的。代理后,js、css 和其他链接将重定向到自定义 404 错误页面,该页面是源应用程序的一部分。我已经通过修改代码解决了这个问题。
关于URL 重写后 Javascript 内容类型被更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44809417/