How to create links and redirects in Marketing Cloud

How to create links and redirects in Marketing Cloud

The matter seems trivial but still requires close attention when passing URL parameters.

Links and URLs

Let’s say we want to create a simple link to a marketing cloud web page.

We then have 2 choices: make an absolute or a relative URL.

It’s ill advised to use an absolute URL, since the domain name or the page link might change with time.

Therefore, using the method CloudPagesURL seems the most appropriate and only requires the id of your page, which can be found in each page’s parameters.

<a href="%%=CloudPagesURL(1234)=%%"></a>

But in case of links in the HTML emails, this method is not enough. As a matter of fact, using CloudPagesURL in the href attribute of an <a> tag will most likely result in a broken link because of the automatically added parameters (such as tracking parameters and so on).

<a href="%%=CloudPagesURL(1234)=%%?color=blue"></a>

To avoid the broken links, please use RedirectTo and Concat method. This will create a proper URL string with every additional parameter and the correct separator.

<a href="%%=RedirectTo(CONCAT(CloudPagesURL(1234),'?color=blue'))=%%"></a>

Passing parameters

Passing parameters with CloudPagesURL is very easy. Just follow the page’s id with one or multiple key value pairs separated by a comma.

<a href="%%=RedirectTo(CONCAT(CloudPagesURL(1234,'color','blue')))=%%"></a>

The best part is that every parameter will get automatically encoded and you don’t have to do it separately yourself with Base64Encode or any other method.

The parameters can then be fetched with a simple RequestParameter method without even decoding them.

	SET @Color = RequestParameter('color')

Use case #1

Consider a situation when a redirect to the same page is required, to change the language for instance.

We can add the language parameter to the CloudPagesURL method.

<a href="%%=RedirectTo(CONCAT(CloudPagesURL(1234,'language','en')))=%%">EN</a>
<a href="%%=RedirectTo(CONCAT(CloudPagesURL(1234,'language','ru')))=%%">RU</a>

In this case, the language will be encrypted in the query string parameter ?qs= and can be retrieved with AMPscript.

	SET @Language = RequestParameter('language')

But what if we don’t want the language to be encrypted? Here is what we can do:

<a href="%%=RedirectTo(CONCAT(CloudPagesURL(1234),'?language=en'))=%%">EN</a>
<a href="%%=RedirectTo(CONCAT(CloudPagesURL(1234),'?language=ru'))=%%">RU</a>

Use case #2

Consider a situation when we need to redirect the customer to a different page (in a different language possibly) but keep the parameters that we currently have in the URL.

In this case, we can take everything that comes after the ? in the URL and simply add it to the different URLs generated by the CloudPagesURL methods.

In other words:

  • We take
  • Extract ?utm_medium=email
  • Add ?utm_medium=email to some other URLs

Here is what it can look like if we decide to use Regex for slicing the URL:


SET @URL = RequestParameter('PAGEURL')
SET @URLRegEx = "^(http[s]?:\/\/?[^:\/\s]+[^\/]*?\/\w+\.)*([^#?\s]+)(\?([^#]*))?(#(.*))?$"
SET @URLTail = RegExMatch(@URL, @URLRegEx, 3)
<a href="%%=RedirectTo(CONCAT(CloudPagesURL(1234),@URLTail))=%%">EN</a>
<a href="%%=RedirectTo(CONCAT(CloudPagesURL(5678),@URLTail))=%%">RU</a>
<a href="%%=RedirectTo(CONCAT(CloudPagesURL(9123),@URLTail))=%%">LT</a>


Not unlike RedirectTo method, Redirect requires Concat to function properly.

Use CloudPagesURL method within just as you did before.


Have I missed anything?

Please poke me with a sharp comment below or use the contact form.

  1. Great explanation, thank you!
    Could you also include redirecting to the same page, e.g. to change its language?

  2. %%[
    Redirect and CloudpagesURL does not work any more. Error generated “This function is only allowed in in content with an HTTP context.\r\n Function: Redirect(CONCAT(CloudPagesURL….” Is there something missing in the example?

  3. Chris, I re-tested it on a Cloud page and everything works fine. Are you trying to run it from an email or SMS?

  4. Is there any way to shorten, change, or remove the qs string after the link? We have one that’s awfully long. Would we be able to map and replace this with email address?

  5. Sam, the goal of the qs string is to encrypt the data in the URL in such a way that nobody would be able de decrypt it in a million years. You can’t shorten it, but what you can do is to stop encrypting the parameters by removing the CloudPagesURL function.

  6. I wish that they would build marketing cloud in the builder that coded things correctly because right now it codes the direct link to the pages with “%%=CloudPagesURL(1234)=%% and when trying to have a complex journey from a simple form to a trigger email to another page then if they click a link to a form all the users data is passed along so the users form is partially filled in based on the first form they filled in. Thanks for clarifying with the redirect because I want our users to not having to fill in a whole form if we have their data already.

  7. How can i redirect to a Cloudpage which is located in a different BU CloudPageURL needs the PageID but this is not working as the cloud page is located in a different BU.

    Can i somehow use the URL of the cloudpage which is in parent BU instead on PageID?

Leave a Reply

Your email address will not be published.

Up Next:

How to create a Form Handler and avoid Smart Capture

How to create a Form Handler and avoid Smart Capture