Use createAbsoluteUrl() for the link you want to have with https schema. Like:
echo $this->createAbsoluteUrl('user/login', array(), 'https');
Then create a base controller like this and put it in your components folder:
class BaseController extends CController
{
public function beforeAction($action)
{
if (parent::beforeAction($action))
{
if (Yii::app()->request->isSecureConnection)
{
// Either do this if you want https for an action:
if ($action !== 'actionName')
{
$this->redirect($this->createAbsoluteUrl("{$this->id}/{$action->id}", array(), 'http'), true, 301);
}
// Or otherwise this if you want https for a whole controller:
if ($this->id !== 'controllerName')
{
$this->redirect($this->createAbsoluteUrl("{$this->id}/{$action->id}", array(), 'http'), true, 301);
}
// Of course you can also check both, controller name and action name if needed
}
return true;
}
}
}
Then you extend your controller classes from the BaseController like this:
class UserController extends BaseController
{
...
}
Now on each request the base controller checks if we’re on a secure https connection. If that’s the case we redirect to the http url if the controller and/or action is not allowed to run under https.
Kind of dirty, but Yii’s url management isn’t very dynamic without modifications. If you want better solution, you may look at CUrlRule and CUrlManager::createUrlRule(). You could add a custom attribute $allowHttps to your custom UrlRule class and redirect from there to the http url. Then in your config you could do:
'urlRules' => array(
...
'user/login' => array('user/login', 'allowHttps' => false),
...
),
Though, maybe someone got a better solution in mind.