Zend Framework redirects in the front controller plugin causes a redirect loop

class Ef_AppSecurity extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request) { if (!Zend_Auth::getInstance()->getIdentity()) { $redirect = new Zend_Controller_Action_Helper_Redirector(); $redirect->gotoSimpleAndExit('login', 'auth'); } } } 

It redirects and changes the new URL, however in the browser it creates a redirect loop. I am wondering if a problem could arise from apache mod_rewrite settings.

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L] 
+4
source share
2 answers

Do not add this plugin to login / auth, or; extend the criteria to

 if (!Zend_Auth::getInstance()->getIdentity() && $this->getRequest()->getControllerName() != 'login' && $this->getRequest()->getActionName() != 'auth') 
+6
source

You must add an exception to the login page. Otherwise, it will be redirected as well as back to itself, causing a loop.

So, if your login page is in the controller with the names "login" and "index", you need to add an exception for this page, and any other page can process the form.

  if (!Zend_Auth::getInstance()->getIdentity() && $this->getRequest()->getControllerName() != 'login' && $this->getRequest()->getActionName() != 'index') ) { $redirect = new Zend_Controller_Action_Helper_Redirector(); $redirect->gotoSimpleAndExit('login', 'index'); } 
0
source

Source: https://habr.com/ru/post/1387324/


All Articles