phpiisurl-rewritingevent-tracking

IIS URL Rewrite redirect to image to track email views


I am trying to build an email tracker based on the folder name that requests the image.

Example:

https://www.example.com/image/123/spager.gif

which need to be turned into this

https://www.example.com/image/index.php?id=123

which in return would serve the spacer.gif image.

Is this doable? And if yes, what am I missing?

So fare I got this:

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);
?>

but I am getting the error:

The page cannot be displayed because an internal server error has occurred.

and nothing in the log files that would help me get a hint on what is not working.


Solution

  • I had the config file inside the image folder, so dropped image as part of the match.

    Also <match ... /> was missing /> at the end.

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