diff --git a/auth/shibboleth/logout.php b/auth/shibboleth/logout.php
index <HASH>..<HASH> 100644
--- a/auth/shibboleth/logout.php
+++ b/auth/shibboleth/logout.php
@@ -26,13 +26,14 @@ if (!is_enabled_auth('shibboleth')) {
 $inputstream = file_get_contents("php://input");
 if ($action == 'logout' && !empty($redirect)) {
 
-    if ($USER->auth == 'shibboleth') {
-        // Logout out user from application.
+    if (isloggedin($USER) && $USER->auth == 'shibboleth') {
+        // Logout user from application.
         require_logout();
-         // Finally, send user to the return URL.
-        redirect($redirect);
     }
 
+    // Finally, send user to the return URL.
+    redirect($redirect);
+
 } else if (!empty($inputstream)) {
 
     // Back channel logout.
MDL-<I> shibboleth: handle users who are logged out

If the user is (already) logged out, do not access $USER->auth and redirect him to the return URL.