- // don't redirect user to the deleted entry
- return $this->redirect($url !== $request->headers->get('referer') ? $request->headers->get('referer') : $this->generateUrl('homepage'));
+ // don't redirect user to the deleted entry (check that the referer doesn't end with the same url)
+ $referer = $request->headers->get('referer');
+ $to = (1 !== preg_match('#'.$url.'$#i', $referer) ? $referer : null);
+
+ $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($to);
+
+ return $this->redirect($redirectUrl);