redirect
| Rivet Tcl Commands and Variables |

## Name

redirect — Interrupt processing and divert to a new URL

## Synopsis

::rivet::redirect ?URL? ?permanent?

## Description

::rivet::redirect diverts the browser to a new URL and marks the redirection as either permanent in the browser local cache or non permanent (default). Calling ::rivet::redirect causes the script execution to interrupt and control passes to AbortScript, if such script is set, by calling ::rivet::abort_page and passing as abort code a dictionary with 2 keys:

- error_code: string literal 'redirect'
- location: the URL the browser will be redirected to

::rivet::redirect drives the redirection by setting the 301 (permanent = 1: permanent redirect) or 302 (permanent = 0: non permanent redirect) and attempts to discard the output the script might have already placed in the stdout channel buffer. The “permanent” argument can also be any of the other HTTP status codes. This is handy for returning one the 3xx status codes dedicated to the HTTP request redirection The command can fail if

- A flush stdout has already been called before ::rivet::redirect thus causing the HTTP headers to be sent
- The channel buffer has been flushed already by calling flush stdout or because the Rivet channel internal buffer was full

The stdout channel, like any Tcl channels, can be manipulated and if needed its internal buffer stretched.

raw_post |  | read_file