The redirect function allows you to redirect to another URL.

{% do redirect('') %}

You can wrap the redirect function in an if statement. If the condition is not met then the redirect does not take place.

{% if color == 'blue' %}
    {% do redirect('/my-blue-page') %}
{% endif %}


The redirect function has the following signature.

redirect(url, status)

Argument Description


The URL to redirect to. 

The URL can be a full URL or an absolute URL within the same site.

{% do redirect('') %}

{% do redirect('/another/page/in-my-site') %}

The URL can be a string or it can be pass through a variable.

{% set url = '' %}
{% do redirect(url) %}

{% do redirect(appUrls.home) %}


The numeric HTTP status code for the redirect.

The following values are accepted:

  • 301
  • 301
  • 303
  • 304

If a status code is not passed then 302 is used. In almost all cases, 302 is the status that you want to use.

< Back to the list of functions