Go to page content

resource_redirect

Redirect to another url.

This Webmachine resource redirects a request to another url.  The url can be a fixed url, the location of a fixed page id or a dispatch list.

Example dispatch rule:

{redir, ["plop"], resource_redirect, [{url, "/newplop"}, {is_permanent, true}]} 

This redirects any requests of "/plop" permanently to "/newplop".

It has the following dispatch options:

OptionDescriptionExample
urlThe url of the new location the browser is sent to.{url, "/example"}
is_permanentUse a permanent (301) or temporary redirect (307). Defaults to false.{is_permanent, false}
dispatchName of a dispatch rule to use for the location url.  All arguments (except dispatch and is_permanent) are used as parameters for the dispatch rule.{dispatch, admin}
idId of the page to redirect to. The resource will redirect to the page_url of this id.  The id can be an integer or the name of the page (use an atom or a binary).{id, 123}
qargs

A list with querystring arguments to use in the new dispatch rule.

Specifies what query (or dispatch) arguments to use from this dispatch rule into the dispatch rule that is being redirected to.

{qargs, [id,slug]}

This resource does only handle request arguments that are specifically noted in the "qargs" list (and then only when the "dispatch" argument is set).

Example

A dispatch rule that always redirects /foo/12312/slug to /bar/12312/slug:

{bar, ["bar", id, slug], resource_page, [{template, "bar.tpl"}]},
{bar_redirect, ["foo", id, slug], resource_redirect, [{dispatch, bar}, {qargs, [id,slug]}]}

This page is part of the Zotonic documentation, which is licensed under the Apache License 2.0.