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标签。

enter image description here

enter image description here

,

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...