出站重写规则中的重写提供程序错误 [英] The rewrite provider error in an outbound rewrite rule
问题描述
我支持包含许多.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="<head>" />
<action type="Rewrite" value="<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>" />
</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="<body(\s*[^>]*)>" />
<action type="Rewrite" value="<body{R:1}><noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-WR7TNHP" height="0" width="0" style="display:none;visibility:hidden"></iframe></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屋!