[英]The rewrite provider error in an outbound rewrite rule
I am supporting a website with many.html files.我正在支持一个包含 many.html 文件的网站。 The site runs in IIS 10 on Windows 2016. Now I am asked to insert the following Google Tag Manager code immediately after <head>
.该站点在 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>
Obviously, inserting this piece of code manually into each html file is a bad idea in many aspects.显然,将这段代码手动插入到每个 html 文件中在很多方面都是一个坏主意。 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.基本上,这个想法是用<head>
<head>
和上面的代码替换响应中的 <head>。 I entered it through the Edit Outbound Rule interface in IIS and the following is what I got in web.config after saving it:我通过 IIS 中的 Edit Outbound Rule 界面输入了它,以下是我保存后在 web.config 中得到的内容:
<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>
However, I saw this error message in IIS when saving it in the Edit Outbound Rule interface.但是,我在编辑出站规则界面中保存时在 IIS 中看到了此错误消息。
The rewrite provider "w[l]=w[l]||[];w[l].push({'xyz.start'" does not exist.
If I load a HTML page, the browser displays this error:如果我加载 HTML 页面,浏览器会显示此错误:
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.非常感谢任何帮助或输入。
UPDATE 1更新 1
Before this post, I looked at and tried this piece (there is no example for my situation)在这篇文章之前,我查看并尝试了这篇文章(我的情况没有示例)
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
I also read and tried this piece我也阅读并尝试了这篇文章
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
I wasn't able to get it work.我无法让它工作。 Basically, no clue how to make it work.基本上,不知道如何使它工作。
UPDATE 2更新 2
I was also asked to insert this piece of code immediately after <body>
tag, and I was able to use an outbound rule successfully.我还被要求在<body>
标记之后立即插入这段代码,并且我能够成功使用出站规则。
<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/how-to-escape-curly-brackets-in-url-rewrite-rule https://blogs.iis.net/danielvl/how-to-escape-curly-brackets-in-url-rewrite-rule
Basically, the solution is replace opening {
with this function:基本上,解决方案是用这个 function 替换打开{
:
{UrlDecode:%7B}
Hope this would help somebody in the future.希望这对将来的人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.