微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

iis-7 – 如何使用IIS7修复CSS文件内链接的URL重写

我正在尝试为我的朋友在家里设置一个代理服务器.我目前正在关注网站上的教程( http://blogs.iis.net/carlosag/archive/2010/04/01/setting-up-a-reverse-proxy-using-iis-url-rewrite-and-arr.aspx),但我遇到了一个奇怪的问题.

我已经尝试将/ pandora重定向到www.pandora.com但CSS文件中的链接没有改变.此外,它们仍然链接到localhost / img / ..路径.应将它们重定向到localhost / pandora / img / ..路径.

来自第一个网页的sniplet

<link rel="shortcut icon" href="/pandora/favicon.ico" type="image/x-icon" />
<link rel="icon" type="image/ico" href="/pandora/favicon.ico" />

<Meta name="viewport" content="width=device-width,initial-scale=1.0">

<link rel="stylesheet" href="css/compiled.css?v=95845013">
<link id="valanceStyle" rel="stylesheet" type="text/css" href="/pandora/static/valances/pandora/default/design.css"/>

你们能帮帮我解决这个问题吗?

解决方法

可以将出站重写规则与ARR结合使用.以下规则应该这样做:
<system.webServer>
    <rewrite>
        <outboundRules>
            <rule name="Rewrite image URLs in CSS response" preCondition="IsCSS">
                <match pattern="localhost/img/" />
                <action type="Rewrite" value="localhost/pandora/img/" />
            </rule>
            <preConditions>
                <preCondition name="IsCSS">
                    <add input="{RESPONSE_CONTENT_TYPE}" pattern="text/css" />
                </preCondition>
            </preConditions>
        </outboundRules>
    </rewrite>
</system.webServer>

您当然应该使用正确的域名替换localhost.如果要从其他域名重写,则匹配标记应包含要替换的域名,操作标记应包含要替换的域名.

由于CSS不是HTML,因此您无法使用URL重写模块的标记过滤功能.因此,它只能对CSS文件的整个内容进行正则表达式匹配,这可能对大型CSS文件造成cpu密集.如果您知道需要替换多少个网址,则可以将eventss =“x”属性添加到< match>标记以限制URL重写模块必须查找的匹配数.还可以尝试将CS​​S规则移动到CSS文件的顶部.例如.:

<action type="Rewrite" value="localhost/pandora/img/" occurrences="3" />

您还可以在IIS中启用用户模式缓存,并将属性rewriteBeforeCache =“yes”添加到< outboundRules>标记让IIS缓存重写的内容.例如.:

<outboundRules rewriteBeforeCache="yes">

有关出站重写规则的更多有用信息和提示可在this blog post中找到.

原文地址:https://www.jb51.cc/css/215211.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。