如何让 IIS UrlRewrite 适当地处理 CSS 传送的 woff 文件?

如何让 IIS UrlRewrite 适当地处理 CSS 传送的 woff 文件?

背景:Azure;Windows Server 2012;IIS 8

首先,这是(已删除)web.config供参考

        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="false">
                    <match url="(.*)" />
                    <action type="Rewrite" url="https://www.khatam.com/{R:1}" logRewrittenUrl="true" />
                    <serverVariables>
                        <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
                        <set name="HTTP_ACCEPT_ENCODING" value="" />
                    </serverVariables>
                </rule>
                <rule name="Capture Http Origin Header" enabled="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
                        <add input="{HTTP_ORIGIN}" pattern=".+" />
                    </conditions>
                    <serverVariables>
                        <set name="CAPTURED_ORIGIN" value="{C:0}" />
                    </serverVariables>
                    <action type="None" />
                </rule>
            </rules>
            <outboundRules>
                <clear />
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                    <match filterByTags="None" pattern="^http(s)?://www.khatam.com/(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
                    <action type="Rewrite" value="http{R:1}://jamuni.pemaish.com.au/{R:2}" />
                </rule>
                
                <rule name="Rewrite mundrjatzxera Assets" preCondition="ResponseIsHtml1" enabled="true">
                    <match filterByTags="None" pattern="^/(mundrjat/zxera/.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
                    <action type="Rewrite" value="https://www.khatam.com/{R:1}" />
                </rule>
                
                <rule name="Rewrite Source Srcset in Picture Assets" preCondition="ResponseIsHtml1" enabled="true">
                    <match filterByTags="CustomTags" customTags="Source Srcset in Picture" pattern=",?\/(mundrjat\/zxera\/\S+\s\d+w)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
                    <action type="Rewrite" value="https://www.khatam.com/{R:1}" />
                </rule>

                <rule name="Rewrite X-Frame-Options" enabled="true" patternSyntax="Wildcard">
                    <match serverVariable="RESPONSE_X-Frame-Options" pattern="*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
                    <action type="Rewrite" />
                </rule>
                
                <rule name="Set-Access-Control-Allow-Origin for known origins" enabled="true">
                    <match serverVariable="RESPONSE_Access-Control-Allow-Origin" pattern=".+" negate="true" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
                    <action type="Rewrite" value="{CAPTURED_ORIGIN}" />
                </rule>
                
                <rule name="Restore Accept Encoding" preCondition="Needs to Restore Original Accept Encoding" enabled="true">
                    <match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
                    <action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
                </rule>
                
                <preConditions>
                    <preCondition name="ResponseIsCss">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/css" />
                    </preCondition>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                    <preCondition name="ResponseIsEverything">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/(.+)$" />
                    </preCondition>
                    <preCondition name="Needs to Restore Original Accept Encoding">
                        <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".*" />
                    </preCondition>
                </preConditions>
                
                <customTags>
                    <tags name="Source Srcset in Picture">
                        <tag name="source" attribute="srcset" />
                    </tags>
                </customTags>
            </outboundRules>
        </rewrite>
...

<httpProtocol>
    <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
    </customHeaders>
</httpProtocol>

我们正在为客户反向代理一个网站。代理网站是www.khatam.com。执行代理的服务器是(是的,我会说乌尔都语,虽然说得不是很好。)客户的网站中会有一个 IFRAME,它会通过我们的服务器与 的网站jamuni.pemaish.com.au进行交互。khatam.comjamuni

到目前为止一切顺利:客户能够通过其 IFRAME 运行 khatam 网站中的所有内容。不太好的是,其中一个 CSS 文件中引用了 WOFF 文件,但这些文件无法加载。

在浏览器的 devtools 中(正在渲染 IFRAME)所有 woff 都是红色的,常规标题为

Request URL: https://jamuni.pemaish.com.au/vgera.mukljuga/jugabisbis/mukljuga/khatam/vesael/icomoon.woff
Request Method: GET
Status Code: 500 URL Rewrite Module Error.
Remote Address: XXX.XXX.XXX.XXX:443
Referrer Policy: no-referrer-when-downgrade

我曾尝试编写一条规则来更改 CSS,即

<rule name="Rewrite vgera.mukljuga Assets" preCondition="ResponseIsCss" enabled="true">
       <match filterByTags="None" pattern="url\((khatam/vesael/.*?.woff)" />
       <conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
       <action type="Rewrite" value="url(https://www.khatam.com/vgera.mukljuga/jugabisbis/mukljuga/{R:1}" />
</rule>

但无论指定目标还是中间体,我仍然会收到 500 错误。现在,当我重新阅读这篇文章时,我想知道我是否得到了一个重写的输出,该输出被另一个重写所拾取,从而导致循环或竞争。如果我从上面的常规中获取链接并将其放入浏览器的地址栏中,我会得到一个 woff 文件,表明两个或多个规则之间存在争用。

CSS 规则是相对路径的。以下是其中一条:

@font-face {
    font-family: trade-gothic-condensed;
    src: url(khatam/vesael/tradegothicltcom-bdcn20-webfont.woff) format("woff");
    font-weight: 700;
    font-style: normal;
    -webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}

欢迎提出建议。

相关内容