DS9 DS9 - 10 days ago 4
Ajax Question

createAbsoluteUrl issue in yii

I have one ajax request in site, it has a code like below:

type: "POST",
url: '<?php echo Yii::app()->createAbsoluteUrl("site/checkstatus"); ?>',
}).success(function(){ dontBlock = false; }).complete(function(){

Now it is working fine in live site. It has a domain like https://example.com. Now i have to move this site into load balancing server. So i have created domain like https://ww.example.com and linked up that domain with load balancer server. But now the ajax request is sent using http instead of https.

I have checked the documentation and it says that schema to use (e.g. http, https). If empty, the schema used for the current request will be used. So suppose i am visited the site using URL like this: https://ww.example.com/index.php?r=controller/action then shouldn't it take the https request?


Your load balancer may be incorrectly configured to pass on HTTPS requests. Your load balancer may receive HTTPS requests but passes them on to your application servers via HTTP. As such the request from the application server's point of view is a HTTP request.

The function determining the schema is CHttpRequest::getIsSecureConnection as below:

public function getIsSecureConnection() {
    return isset($_SERVER['HTTPS']) && (strcasecmp($_SERVER['HTTPS'],'on')===0 || $_SERVER['HTTPS']==1)
        || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'],'https')===0;

To fix it ensure that your load balancer inserts a HTTP_X_FORWARDED_PROTO header when passing on the request to the application servers.