Skip to content

Miscellaneous

redirectTo()

redirectTo() — returns any

Redirects the browser to the supplied controller/action/key, route or back to the referring page. Internally, this function uses the URLFor function to build the link and the cflocation tag to perform the redirect.

NameTypeRequiredDefaultDescription
backbooleanyesfalseSet to true to redirect back to the referring page.
addTokenbooleanyesfalseSee documentation for your CFML engine’s implementation of cflocation.
statusCodenumericyes302See documentation for your CFML engine’s implementation of cflocation.
routestringyesName of a route that you have configured in config/routes.cfm.
controllerstringyesName of the controller to include in the URL.
actionstringyesName of the action to include in the URL.
keyanyyesKey(s) to include in the URL.
paramsstringyesAny additional parameters to be set in the query string (example: wheels=cool&x=y). Please note that CFWheels uses the & and = characters to split the parameters and encode them properly for you (using URLEncodedFormat() internally). However, if you need to pass in & or = as part of the value, then you need to encode them (and only them), example: a=cats%26dogs%3Dtrouble!&b=1.
anchorstringyesSets an anchor name to be appended to the path.
onlyPathbooleanyestrueIf true, returns only the relative URL (no protocol, host name or port).
hoststringyesSet this to override the current host.
protocolstringyesSet this to override the current protocol.
portnumericyes0Set this to override the current port number.
urlstringyesRedirect to an external URL.
delaybooleanyesfalseSet to true to delay the redirection until after the rest of your action code has executed.
// Redirect to an action after successfully saving a user
if (user.save())
{
	redirectTo(action="saveSuccessful");
}

// Redirect to a specific page on a secure server
redirectTo(controller="checkout", action="start", params="type=express", protocol="https");

// Redirect to a route specified in `config/routes.cfm` and pass in the screen name that the route takes
redirectTo(route="profile", screenName="Joe");

// Redirect back to the page the user came from
redirectTo(back=true);