htaccess https redirect only on specific Zend Frameworks controller/actions

前端 未结 4 1442
夕颜
夕颜 2021-01-27 05:41

I\'m new to this community, but I\'ve found it really useful time to time.

I\'ve searched for the answer a lot, but I didn\'t find anything like I need. I\'ve tried to s

4条回答
  •  隐瞒了意图╮
    2021-01-27 06:30

    A method we use to redirect to https is to leave the default Zend Framework .htaccess settings and create an action helper to redirect to https when required. Our action helper code is:

    getActionController()->getHelper('Redirector');
                $redirector->goToUrlAndExit('https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
            }
        }
    }
    

    Then when you are in a controller action that you need to be accessed via HTTPS you simply call this function at the beginning:

    $this->_helper->requireSSL();
    

    Also, here is another method for using action helpers that is a little more detailed if you need it:

    http://juriansluiman.nl/en/article/110/in-control-of-https-for-action-controllers

    Hope that helps!

提交回复
热议问题