redirectTo()
Description
Redirects the browser to the supplied controller/action/key, route or back to the referring page. Internally It uses the URLFor() function to build the link and the cflocation tag to perform the redirect.
Function Syntax
redirectTo([ back, addToken, statusCode, route, controller, action, key, params, anchor, onlyPath, host, protocol, port ])
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
back |
boolean |
No | false |
Set to true to redirect back to the referring page. |
addToken |
boolean |
No | false |
See documentation for cflocation. |
statusCode |
numeric |
No | 302 |
See documentation for cflocation. |
route |
string |
No | |
Name of a route that you have configured in config/routes.cfm. |
controller |
string |
No | |
Name of the controller to include in the URL. |
action |
string |
No | |
Name of the action to include in the URL. |
key |
any |
No | |
Key(s) to include in the URL. |
params |
string |
No | |
Any additional params to be set in the query string. |
anchor |
string |
No | |
Sets an anchor name to be appended to the path. |
onlyPath |
boolean |
No | true |
If true, returns only the relative URL (no protocol, host name or port). |
host |
string |
No | |
Set this to override the current host. |
protocol |
string |
No | |
Set this to override the current protocol. |
port |
numeric |
No | 0 |
Set this to override the current port number. |
Examples
<!--- Redirect to an action after successfully saving a user --->
<cfif user.save()>
<cfset redirectTo(action="saveSuccessful")>
</cfif>
<!--- Redirect to a specific page on a secure server --->
<cfset 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 --->
<cfset redirectTo(route="profile", screenName="Joe")>
<!--- Redirect back to the page the user came from --->
<cfset redirectTo(back=true)>
