Jorge Valle

Jorge Valle

Jorge Valle is a front end developer with a particular passion for, and expertise in, JavaScript and user interfaces. Lately, he's also been diving into machine learning.

IIS redirects that retain query strings

Short URLs are great for marketing purposes, especially when they are destined for print. Users will find typing the following URL laborious, and will likely not even bother to do it.

Short URLs are great for marketing purposes, especially when they are destined for print.

yourdomain.com/some/long/path/to/the/resource

Instead, we create a short URL like the following one.

yourdomain.com/shorturl

We then redirect this one to the longer one. Helpful. Common. Nothing groundbreaking here.

However, there's a common gotcha. These short URLs are also often used in digital advertising, and these platforms append query strings for tracking purposes.

For example, an email marketing platform might append the following query strings.

yourdomain.com/shorturl?source=your-platform&campaign=your-campaign

If we're not careful with our redirects at a server level, these query strings might get stripped out. This could muddle your analytics. Also, depending on your configuration, the redirect might entirely 404.

To avoid this, I like to use the following IIS rule in the web.config.

This is referencing an external file called rewritemap.config, where all the key/value pairs live. I will explain how to set this up in a future blog post.


Books, patrons and coffee in Caffè San Marco, Trieste