3

We have some printed material with a QR code. The code was supposed to go to a landing page so we could keep track of how many times a PDF file was downloaded and by who, but somewhere along the line it was changed to point to the direct URL for the PDF.
The books are printed, so it's too late to fix that error.

What I would like to do is change the name of the PDF to something else, then create a rewrite rule in IIS that will listen for the URL that is in the QR code and redirect to the original landing page.
Apparently I'm doing something wrong.

            <rule name="Training Packet download" stopProcessing="true">
                <match url="^pdf/Mini%20Packet-takeaways-Parts.pdf$" />
                <action type="Rewrite" url="pdf/seminarlanding.php" />
            </rule>

It keeps going to the 404 error page, even though this rule is at the top of the list.

Tried it with exact match, and with redirect:

            <rule name="Training Packet download" patternSyntax="ExactMatch" stopProcessing="true">
                <match url="pdf/Mini%20Packet-takeaways-Parts.pdf" />
                <action type="Redirect" url="pdf/seminarlanding.php" />
            </rule>

That still goes to 404. I have a different rewrite rule that does work, and I'm not sure what the difference is.

            <rule name="ViewPost Rewrite" stopProcessing="true">
                <match url="^Community/Forum/([^/]+)/([^/]+)/?([^/]+)?$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="Community/Forum/ViewPost.php?f={R:1}&amp;t={R:2}" />
            </rule>

Tried to make them match even more closely, still 404:

            <rule name="Training Packet download" stopProcessing="true">
                <match url="^pdf/Mini%20Packet-takeaways-Parts.pdf$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="pdf/seminarlanding.php" />
            </rule>
4
  • docs.lextudio.com/blog/… Likely you are hitting Mistake 3 but why not use redirect as action for your case? Commented Sep 17 at 22:01
  • @LexLi I tried Redirect with no difference. I also tried exact match since its a specific file and I don't need any wildcard stuff. I added an example of a different similar rule that works perfectly. I'm not sure why it would hit mistake 3 when I'm redirecting to a different file in the same directory? Commented Sep 18 at 13:28
  • Failed request tracing can tell what's exactly wrong, so have you enabled it? My blog post pointed that out. Commented Sep 18 at 13:46
  • @LexLi The graphic designer included a space in the file name in the QR code, which of course becomes a %20, so I put that in the match url. Apparently that was a mistake, in case you want something for Mistake 4. I replaced it with an actual space in the rule and it suddenly started working. Commented Sep 18 at 13:50

1 Answer 1

1

Threw a lot of spaghetti at the wall, and I don't know why this works:

            <rule name="Training Packet download" stopProcessing="true">
                <match url="^pdf/Mini Packet-takeaways-Parts.pdf$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="pdf/seminarlanding.php" />
            </rule>

All I did was replace the %20 with an actual space in the rule, and it figured it out. I'm going to have to teach the graphic designer how to name a file :)

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.