Redirect

Redirect

{% redirect %}

Redirects a "302 Found" HTTP response pointing to the location of the target. This is slower than using built-in redirects but is useful when other variables, processing, or conditionals need to be evaluated first.

Examples

Redirect to restricted page if permission is missing

Copy
{% if page.restrictiontype.is_valid and page.restrictionpage.is_valid %}
{% var restrictiontype = page.restrictiontype.value %}
{% unless permissions[restrictiontype].allowed %}
{% redirect page.restrictionpage %}
{% endunless %}
{% endif %}

Redirect to requested page with login path appended

Copy
{% if user.guest %}
{% redirect request.path | url_encode | prepend: "/log-in?r=" %}
{% endif %}