{redirect:url:code}

Description

Sends the visitor straight to another URL the moment the engine reaches this command, then stops rendering the rest of the page. It is meant for Site-module spots and pages: use it to route a request to another branch, enforce a canonical domain, or bounce to a login page. The redirect only fires when the URL (first parameter) is non-empty - an empty URL is a no-op that prints nothing and lets the page continue, which is exactly why the conditional forms wrap the URL in ifset or ifeq with an empty true-branch. Always escape the colon in the scheme as http#:// (or https#://) so the engine does not read it as a parameter separator. The optional second parameter is the HTTP status code and defaults to 301 (Moved Permanently); pass 302 for a temporary redirect. The command itself never outputs any text.

Parameters

url required default (none)

The destination URL. Escape the colon in the scheme as http#:// (or https#://) so the engine does not treat it as a parameter separator. If this value is empty the command does nothing - no redirect and no output - which is what makes the conditional forms (an ifset or ifeq with an empty true-branch) safe.

code optional default 301

The HTTP status code sent with the Location header. 301 means the page moved permanently (browsers, caches and search engines should remember the new URL); 302 is a temporary redirect. Defaults to 301.

Allowed values 301 = Moved Permanently (the default); 302 = Found, a temporary redirect

Examples

test[{redirect:}]
Expected[]
Actual[]
The redirect only fires when the first parameter is non-empty. With no URL the command outputs nothing and the page keeps rendering. This is the no-op the conditional patterns below rely on.
test[{redirect:{ifset:x::http#://example.org/new-page}}]
Expected[]
Actual[]
The production shape: {redirect:{ifset:COND::URL}}. ifset returns the empty middle branch when COND is set, so no redirect happens; it returns URL (the third branch) only when COND is empty. Swap COND for a runtime value such as {xid} to redirect only when that value is missing. Here COND is the literal x (set), so this stays a safe no-op. The colon in the scheme is escaped as http#:// so it is not read as a separator.
test[{redirect:{ifeq:example.org:example.org::https#://example.org/}}]
Expected[]
Actual[]
A common Site-module use: force one domain. {ifeq:HOST:example.org::https#://example.org/} returns the empty branch when HOST already equals example.org (so no redirect), and the canonical URL otherwise. In production HOST is {server:HTTP_HOST}; here both sides are the literal example.org so the equal branch wins and nothing happens.
test[{redirect::302}]
Expected[]
Actual[]
The second parameter is the HTTP status code, but it only matters when a URL is present. With an empty URL the command is still a no-op regardless of the code. A real temporary redirect looks like {redirect:http#://example.org/:302}.
test[{redirect:{ifset:x::http#://example.org/moved}:302}]
Expected[]
Actual[]
Pass 302 as the second parameter for a temporary redirect (the default is 301, a permanent move). The URL here is guarded by ifset with a set condition x, so the redirect does not fire and the example stays a safe no-op; replace x with a runtime value and drop it to send the 302.