Is it possible to redirect the user to the previous page after login, without needing to use PHP?

Note: I'm not using the default login, i'm using the Freemember add-on.

3 Answers 3


UPDATE: As you're using FreeMember you can take advantage of its built-in PREVIOUS_URL constant:

{exp:freemember:login return="PREVIOUS_URL"}

As detailed in the FreeMember login form docs on GitHub.

If you were using the built in login_form tag instead, I'd suggest you use something like the Current URL extension (EE2 version linked) use the incredibly useful Mo'Variables, to achieve the same effect:

{exp:member:login_form return="{current_url}"}

This works as you can pass a full URL as the return parameter to the login_form tag. That way you're good for any URL structure you might have in your site.

  • Hey Tom, i'm actually using the Freemember add-on but it uses the some of the same tags as the standard login_form tag. Dec 5, 2012 at 11:44
  • Might be worth updating + tagging your qn with that info.
    – Tom Davies
    Dec 5, 2012 at 11:58
  • Oh my gosh. "Grabs more coffee and hangs head in shame". Completely missed that constant on the Github page. Thanks Tom. Dec 5, 2012 at 13:41
  • No worries, easily done :)
    – Tom Davies
    Dec 5, 2012 at 13:43

This should work:

{exp:member:login_form return="{segment_1}/{segment_2}/{segment_3}"}

Maybe you will need to add segment if you have more than 3.

  • Note that this is different to PREVIOUS_URL, which refers to the page they visited before the login page (your answer would just return them to the current page, so would be more useful in a header login form etc). Dec 6, 2012 at 1:49
  • @AdrianMacneil Indeed, I don't deserve my 2 votes ;)
    – pvledoux
    Dec 6, 2012 at 15:16
  • Well, depends on the question. I think you had a good answer for the original question before it was edited :) Dec 7, 2012 at 0:12

There's also this excellent add-on by Objective HTML that adds redirect on login and logout: Authenticate

  • I need to borrow the constant from Free Member. return="PREVIOUS_URL" is a good idea. Dec 5, 2012 at 17:17
  • If you want to keep it consistent, bear in mind that our PREVIOUS_URL constant refers to the page they last visited before the login page, not the current page. See the code if I didn't explain that clearly. Dec 6, 2012 at 1:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.