Redirect to specified URL on logout?

RickM

Well-known member
Hi all,

I've managed to implement a bridge between XenForo and PyroCMS, however need to get this one last thing working before being able to release.

I need to make it so that if on the PyroCMS installation you click logout, it brings you back to the same page after logging out.

I noticed some redirection options in the XenForo logout controllerpublic file but cant seem to get it to work.

Has anyone managed to get this working?

Thanks
 
Can you just add something like name="redirect" value="{$requestPaths.requestUri} to the template?
 
I'll have to give it a try and see. Was hoping to be able to keep it as a standard link (e.g site.com/forums/logout?redirect=site.com/some-page) instead of via POST.

I guess I could do an addon for it if its not possible though.
 
In my testing this only works if you use the "direct" logout link (the one that doesn't ask for confirmation):

Screen shot 2012-03-01 at 2.50.19 PM.webp

If it asks you for logout confirmation then that form does not accept a redirect.
 
Have you solved this yet?

An addon is required to add a redirect to the "confirmation" logout link.

Or you can edit the templates to make that link not ask for confirmation:

Admin CP -> Appearance -> Templates -> navigation_visitor_tab

At the bottom of the template, add the blue code, remove the red code:

Rich (BB code):
		</div>
	</li>
	
	<xen:hook name="navigation_visitor_tabs_end" />

	<li class="navTab PopupClosed"><a href="{xen:link logout, '', '_xfToken={$visitor.csrf_token_page}'}" class="navLink visitorTabItem OverlayTrigger">{xen:phrase log_out}</a></li>
</ul>

That will also allow you to add the redirect code so the user is taken back to the same page after they logout:

Rich (BB code):
		</div>
	</li>
	
	<xen:hook name="navigation_visitor_tabs_end" />

	<li class="navTab PopupClosed"><a href="{xen:link logout, '', '_xfToken={$visitor.csrf_token_page}', 'redirect={$requestPaths.requestUri}'}" class="navLink visitorTabItem OverlayTrigger">{xen:phrase log_out}</a></li>
</ul>
 
An addon is required to add a redirect to the "confirmation" logout link.

Or you can edit the templates to make that link not ask for confirmation:

Admin CP -> Appearance -> Templates -> navigation_visitor_tab

At the bottom of the template, add the blue code, remove the red code:
Thanks mate, that worked. The Overlay window doesn't show anymore.
One more question though. I'm trying to set a redirect to an external link (not a forum path). How do I do that? Redirect=URL?
 
One more question though. I'm trying to set a redirect to an external link (not a forum path). How do I do that? Redirect=URL?

In my testing you cannot specify a full URL for the redirect location.

One option is to create a small PHP script to handle the redirect to the URL:

PHP:
<?php

header("Location: http://www.apple.com/");

?>

Then make the logout link redirect to that script.
 
you could also change this by overwriting XenForo_ControllerPublic_Logout::actionIndex()
this would also allow you easier to define dynamic exit pages(e.g advertisement,redirect to portal index page,etc...)
 
In my testing you cannot specify a full URL for the redirect location.

One option is to create a small PHP script to handle the redirect to the URL:

PHP:
<?php
 
header("Location: http://www.apple.com/");
 
?>

Then make the logout link redirect to that script.
Thanks, that worked just fine ;)
 
I am looking for some help with a similar problem, when my members log out from my site they are redirected to http://www.uk-alliance.com/xenforo/forum/ but I would like it to redirect to http://www.uk-alliance.com/xenforo/ is there a simple edit that will solve this for me ?

My previous posts pretty much cover it. It shows how you can specify a redirect location in the templates. And a small custom script can be used to redirect to full URLs. Do you have any questions about this?
 
yes can you please post a step by step guide as I am a total noobie when it comes to code and editing templates
 
An addon is required to add a redirect to the "confirmation" logout link.

Or you can edit the templates to make that link not ask for confirmation:

Admin CP -> Appearance -> Templates -> navigation_visitor_tab

At the bottom of the template, add the blue code, remove the red code:

That will also allow you to add the redirect code so the user is taken back to the same page after they logout:

Rich (BB code):
</div>
</li>

<xen:hook name="navigation_visitor_tabs_end" />

<li class="navTab PopupClosed"><a href="{xen:link logout, '', '_xfToken={$visitor.csrf_token_page}', 'redirect={$requestPaths.requestUri}'}" class="navLink visitorTabItem OverlayTrigger">{xen:phrase log_out}</a></li>
</ul>


Sorry for the long delay, but could you please please please please please please help me understand the redirect process, I know how to implement the above code, buts thats where I get stuck, where do I actually insert the redirect forum path ? I don't want to redirect to a full url so I assume I don't need to use the above PHP script ? I just want to redirect to my portal page http://www.uk-alliance.com/xenforo/portal/
 
Sorry for the long delay, but could you please please please please please please help me understand the redirect process, I know how to implement the above code, buts thats where I get stuck, where do I actually insert the redirect forum path ? I don't want to redirect to a full url so I assume I don't need to use the above PHP script ? I just want to redirect to my portal page http://www.uk-alliance.com/xenforo/portal/

Replace {$requestPaths.requestUri} with /xenforo/portal/. That should do it.
 
Thank you for the info, it's much appreciated

I have added
Code:
<li class="navTab PopupClosed"><a href="{xen:link logout, '', '_xfToken={$visitor.csrf_token_page}', 'redirect=/xenforo/portal/'}" class="navLink visitorTabItem">{xen:phrase log_out}</a></li>
to the bottom of the navigation_visitor_tab template

That has removed the confirmation box and redirects me to my portal if I log off using this "Log Out" link
Image2.webp

however if I use this "Log Out" link the confirmation box is still removed but it doesn't redirect me to my portal? have I missed something ?

Image 1.webp

Thanks again
 
Top Bottom