Search problem with httpds redirect in appcontroller in cake3

Hi, I found a working solution to change http to https with the code. A htaccess solution with multiple websites has proven to be complicated.

I cant get the below code (search function code below cant work with the code in the Appcontroller)for all of my controllers. The problem is that I have some search functions that call the function again with parameters. Using the below code with initialize means the search function I use no longer works. Is there a way to place the same code for the httpds redirect in the appcontroller not in the initialize function?

   //search controller which no longer works with htttps request from ap controller

 if (($this->request->is('post') || $this->request->is('put'))) {
        //  debug( $this->request->data);
        if (isset($this->request->data['searchFilter'])) {
            $filter_url['controller'] = $this->request->params['controller'];
            $filter_url['action'] = $this->request->params['action'];
            $filter_url['page'] = 1;

            // for each filter we will add a GET parameter for the generated url
            foreach($this->request->data as $name => $value){
                    $filter_url[$name] = urlencode($value);
            //Post params are now GET paramaters
            return $this->redirect($filter_url); //this no longer works with the appcontroller redirect

        }//isset   filter


  //app controller
 public function initialize()
    $this->loadComponent('Security', ['blackHoleCallback' => 'forceSSL']);

 public function beforeFilter(Event $event)



public function forceSSL()
    return $this->redirect('https://' . env('SERVER_NAME') . $this->request->getRequestTarget());

anyone? i really am stuck on this