In the general config settings, one can set a logoutPath, and one can use it using the logoutUrl Global.

However, it says also in the docs: Note that Craft will automatically redirect users to your homepage after going here; there’s no such thing as a “logout page”.

In short; is there any other way to log a user out, besides "triggering" a visit to the predefined logoutPath, which logs users out, but immediately redirects them to the homepage; as it would be more elegant and userfriendly to show some kind of "you've been logged out" message instead first.


Might be going overboard, but you could have a plugin with it's own controller that provided different logout behavior.

But it sounds like to me what you're looking for is something like a 'logoutRedirect' config setting. Probably worth adding to the feedback site!

  • 2
    Thanks! Right, but the confusion comes from -- please correct me if I'm wrong -- that loginUrl actually goes to the specified login page, and stays there, if the user isn't logged in. While logoutUrl logs out, but just goes to the homepage. One would expect these 2 similar variables to act more identical. At least, to me. But it's no biggie. I'll post it on the feedback site, but don't expect much animo for this niche thing. Maybe it's just me.
    – tom
    May 29 '15 at 23:20
  • As of today, I can't find the note about being redirected to the homepage afterwards. Is that still the case? This seems really odd... there's no way after a user logs out to provide some kind of feedback to them? Just a redirect to the homepage?
    – Mike
    May 23 '17 at 9:26

I use a little hack using the retour plugin to redirect request to login page. It's no longer maintained but it's fully working on Craft CMS 2.x versions.

You need to install this plugin and set new redirect:

Legacy URL Pattern: yourHackyLogoutUrl

Destination URL: youFrontEndLoginUrl

Than you need to add a new route in Settings -> Routes

If the URI looks like this: yourHackyLogoutUrl

Load this template: hacky_logout_template

In your hacky_logout_template add this:

{% do craft.cookies.set( "CSRF" ) %}
{% do craft.cookies.set( "PHPSESSID" ) %}
{% exit 404 %}

By visiting yourHackyLogoutUrl Craft CMS picks the template and reset/remove/end user session. If we wouldn't remove it than we would still be logged in. Be careful. The PHPSESSID cookie name is my custom name for php session cookie. You may have it called differently.

Also to call {% do craft.cookies.set( "PHPSESSID" ) %} you must have a cookie plugin installed. I use the cookies plugin by nystudio107. But this is optional as you can reset cookies by javascript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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