【问题标题】:The rewrite provider error in an outbound rewrite rule出站重写规则中的重写提供程序错误
【发布时间】:2021-02-16 02:57:40
【问题描述】:

我正在支持一个包含许多 .html 文件的网站。该站点在 Windows 2016 上的 IIS 10 中运行。现在我被要求在 <head> 之后立即插入以下 Google 跟踪代码管理器代码。

<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'xyz.start':
new Date().getTime(),event:'xyz.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/xyz.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','xyz-ABCDEFG');</script>

显然,将这​​段代码手动插入每个 html 文件在许多方面都是一个坏主意。我正在尝试使用出站规则来完成这项工作。基本上,这个想法是用&lt;head&gt; 和上面的代码替换响应中的&lt;head&gt;。我是通过IIS的Edit Outbound Rule界面输入的,保存后在web.config中得到如下内容:

 <rule name="GTM head" preCondition="IsHTML">
    <match filterByTags="None" pattern="&lt;head>" />
    <action type="Rewrite" value="&lt;head>&lt;script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'xyz.start':new Date().getTime(),event:'xyz.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&amp;l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/xyz.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','xyz-ABCDEFG');&lt;/script>" />
</rule>

但是,在编辑出站规则界面中保存时,我在 IIS 中看到了此错误消息。

The rewrite provider "w[l]=w[l]||[];w[l].push({'xyz.start'" does not exist.

如果我加载 HTML 页面,浏览器会显示此错误:

HTTP Error 500.52 - URL Rewrite Module Error.
The page cannot be displayed because an internal server error has occurred.

非常感谢任何帮助或意见。

更新 1

在这篇文章之前,我查看并尝试了这篇文章(我的情况没有示例)

https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-20-configuration-reference#Tag_Filters

我也阅读并尝试了这篇文章

https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-20-configuration-reference#Tag_Filters

我无法让它工作。基本上,不知道如何使它工作。

更新 2

我还被要求在&lt;body&gt;标签之后立即插入这段代码,并且我能够成功使用出站规则。

<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=xyz-ABCDEFG"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>


<rule name="GTM body" preCondition="IsHTML">
    <match filterByTags="None" pattern="&lt;body(\s*[^>]*)>" />
    <action type="Rewrite" value="&lt;body{R:1}>&lt;noscript>&lt;iframe src=&quot;https://www.googletagmanager.com/ns.html?id=GTM-WR7TNHP&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;display:none;visibility:hidden&quot;>&lt;/iframe>&lt;/noscript>" />
</rule>

【问题讨论】:

  • 感谢您的意见!我在发帖之前看到了那个页面。对我来说困难的是它没有我的情况的例子(替换,而不是重定向)。我不知道该怎么做。尝试了很多东西。没有工作。
  • 您是否尝试使用failed request tracking 获取更多信息?
  • 感谢您的信息。我以前从未尝试过失败的请求跟踪。如果我加载 HTML 页面,我会看到以下错误:HTTP Error 500.52 - URL Rewrite Module Error. The page cannot be displayed because an internal server error has occurred。你认为失败的请求跟踪对我的情况有帮助吗?在这种情况下,IIS 已经首先使用出站重写规则指示错误并且页面加载进一步确认了它?

标签: iis


【解决方案1】:

阅读更多,发现这篇文章:

https://blogs.iis.net/danielvl/how-to-escape-curly-brackets-in-url-rewrite-rule

基本上,解决方案是用这个函数替换打开{

{UrlDecode:%7B}

希望这对将来的某人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-13
    • 1970-01-01
    • 2023-04-08
    相关资源
    最近更新 更多