Posted in: Comments

I was using a regular EPiServer template to generate an email template, which an email service could download and send to subscribers. The template had some dynamic links, e.g. unsubscribe and preferences links. These are defined with tokens in the markup and are replaced when the email is sent by the service. The unsubscribe link looks like:

<a href="%UNSUBSCRIBELINK%">Unsubscribe</a>

Unfortunately this links gets rewritten by the URL rewriter and/or html parser that the rewriter is using.

I was trying to exclude the links and the template in Global by adding them in:

UrlRewriteProvider.AddExcludedPath() 

That did however not work. The links were always rendered like:

<a href="/path/to/template/%UNSUBSCRIBELINK%">Unsubscribe</a>

Thanks to Tobias and an old blog post, we found a workaround. You can add an attribute to the link which stops the rewriter from touching the link. The important part here, besides the attribute, is to add an id to the element as well(!).

<a href="%UNSUBSCRIBELINK%" <%= EPiServer.Web.UrlRewriteProvider.UrlPreventRewriteAttribute %>="true" id="required-id-but-not-used">Unsubscribe</a>