redirect

The redirect function allows you to redirect to another URL.

{% do redirect('http://www.yoursite.com') %}

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 %}

Arguments

The redirect function has the following signature.

redirect(url, status)

Argument Description
url

Required

The URL to redirect to. 

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

{% do redirect('http://www.google.com') %}

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

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

{% set url = 'http://www.mysite.com' %}
{% do redirect(url) %}

{% do redirect(appUrls.home) %}

status

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