出站重写规则中的重写提供程序错误 [英] The rewrite provider error in an outbound rewrite rule

查看:57
本文介绍了出站重写规则中的重写提供程序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am supporting a website with many .html files. The site runs in IIS 10 on Windows 2016. Now I am asked to insert the following Google Tag Manager code immediately after <head>.

<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文件中是一个坏主意.我正在尝试对工作使用出站规则.基本上,该想法是将响应中的< head> 替换为< head> 和以上代码.我是通过IIS中的编辑出站规则"界面输入的,以下是保存后在web.config中得到的内容:

Obviously, inserting this piece of code manually into each html file is a bad idea in many aspects. I am trying to use outbound rules for the job. Basically, the idea is to replace <head> in the response with <head> and the above code. I entered it through the Edit Outbound Rule interface in IIS and the following is what I got in web.config after saving it:

 <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中看到此错误消息.

However, I saw this error message in IIS when saving it in the Edit Outbound Rule interface.

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

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

If I load a HTML page, the browser displays this error:

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

我们非常感谢您的帮助或投入.

Any help or input is really appreciated.

更新1

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

Before this post, I looked at and tried this piece (there is no example for my situation)

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

I also read and tried this piece

我无法使其正常运行.基本上,不知道如何使它起作用.

I wasn't able to get it work. Basically, no clue how to make it work.

更新2

我还被要求在< body> 标记后立即插入这段代码,并且我能够成功使用出站规则.

I was also asked to insert this piece of code immediately after <body> tag, and I was able to use an outbound rule successfully.

<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>

推荐答案

需要更多阅读并找到这篇文章:

Did more reading and found this article:

https://blogs.iis.net/danielvl/如何逃脱curly-brackets-in-url-rewrite-rule

基本上,解决方案是使用以下功能替换打开 {:

Basically, the solution is replace opening { with this function:

{UrlDecode:%7B}

希望这对将来有帮助的人.

Hope this would help somebody in the future.

这篇关于出站重写规则中的重写提供程序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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