View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page


Redirect the requesting user-agent to the given absolute or relative url.


return res.redirect(url);


Argument Type Details
1 url A URL expression (see below for complete specification).
e.g. "" or "/login"


Sails/Express/Koa/Connect support a few forms of redirection, first being a fully qualified URI for redirecting to a different domain:

return res.redirect('');

The second form is the domain-relative redirect. For example, if you were on, the following redirect to /admin would land you at

return res.redirect('/checkout');

return res.redirect('admin/post/new');


Pathname relative redirects are also possible. If you were on, the following redirect would land you at http//

return res.redirect('..');

The final special-case is a back redirect, which allows you to redirect a request back where it came from using the "Referer" (or "Referrer") header (if omitted, redirects to `/` by default)

return res.redirect('back'); ```


  • This method is terminal, meaning it is generally the last line of code your app should run for a given request (hence the advisory usage of return throughout these docs).
  • When your app calls res.redirect(), Sails sends a response with status code 302. This instructs the user-agent to send a new request to the indicated URL. There is no way to force a user-agent to follow redirects, but most clients play nicely.
  • In general, you should not need to use res.redirect() if a request "wants JSON" (i.e. req.wantsJSON).
  • If a request originated from a client, it always "wants JSON". If you do call res.redirect( for a socket request, Sails reroutes the request internally on the server, effectively "forcing" the redirect to take place (i.e. instead of sending a 302 status code, the server simply creates a new request to the redirect URL).
    • As a result, redirects to external domains are not supported for socket requests (although this is technically possible by proxying).
    • This behavior may change to more closely reflect HTTP in future versions of Sails.

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.


We wrote a book!

Get early access to the book
with promotion code: mcneildoc

Get the Book