Kohana HTTPS redirect
To redirect to https in Kohana use the site function in the URL class to create the URL.
eg
$url = URL::site(Route::get('ROUTE_NAME')->uri(), 'https'); Request::Instance()->redirect($url);
To force actions to be loaded using https I do something like this:
The main template controller:
class Controller_Whitelabel extends Controller_Template { public $ssl_required = false; //controller-wide ssl required public $ssl_actions = false; //action specific ssl required public function before() { parent::before(); $this->sslRedirect(); .......... } private function sslRedirect() { $action_name = Request::instance()->action; if ( ($this->ssl_required) || (is_array($this->ssl_actions) && in_array($action_name, $this->ssl_actions) ) ) { if (Request::$protocol == 'http') { Request::Instance()->redirect(URL::site(Request::Instance()->uri, 'https')); } } else { if (Request::$protocol == 'https') { Request::Instance()->redirect(URL::site(Request::Instance()->uri, 'http')); } } }
It allows you to set either all actions to require ssl, or only specific ones.
Example Controller where all actions require ssl:
class Controller_Payment extends Controller_Whitelabel { public $ssl_required = true; ...... }
Example Controller where only the index & list actions require ssl:
class Controller_Payment extends Controller_Whitelabel { public $ssl_actions = array('index', 'list'); public function action_index() { } public function action_list() { } public function action_view() { } }




Great hack, works perfect!