如何解决IIS URL重写重定向到图像以跟踪电子邮件视图
我正在尝试根据请求图像的文件夹名称构建电子邮件跟踪器。
示例:
https://www.example.com/image/123/spager.gif
需要变成这个
https://www.example.com/image/index.php?id=123
作为回报,它将提供spacer.gif图片。
这可行吗?如果是的话,我想念什么?
如此票价我得到了:
web.config:
<rule name="email image tracker">
<match url="^/image/([0-9]+)/spacer.gif">
<action type="Rewrite" url="/image/index.php?id={R:1}" />
</rule>
index.php:
<?php
header('Content-type: image/gif');
$png_image = imagecreate(150,150);
imagecolorallocate($png_image,15,142,210);
?>
但是我得到了错误:
由于发生内部服务器错误,因此无法显示该页面。
日志文件中没有任何内容可以帮助我提示什么不起作用。
解决方法
我认为请求网址应为https://www.example.com/image/123/spacer.gif,而不是https://www.example.com/image/123/spager.gif。
第二,如果您要应用此规则。请设置为
<match url="^image/([0-9]+)/spacer.gif">
代替
<match url="^/image/([0-9]+)/spacer.gif">
此段中不包含第一个斜杠“ /”。
<rule name="email image tracker" enabled="true" stopProcessing="true">
<match url="^image/([0-9]+)/spacer.gif" />
<action type="Rewrite" url="/image/index.php?id={R:1}" />
</rule>
此规则会将/image/123/spacer.gif重写为/image/index.php?id=123。但是,由于php页面需要从https://www.example.com/image/123/spacer.gif请求资源。图片由于循环而损坏。
我认为您可以尝试使用出站规则重写index.php中的src标签。
,我在image文件夹中有配置文件,因此将图像作为匹配的一部分。
还有<match ... />
在末尾缺少/>
。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="email_image_tracker" stopProcessing="true">
<match url="^([0-9]+)/spacer.gif" />
<action type="Rewrite" url="/i/index.php?id={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。