I want createAbsoluteUrl return url starting with http://myexample.com/… which is mainly used in sending out email so that all links in email pointing to desktop url (http://myexample.com)
I’ve done the following in order to ensure that the correct domain is used in canonical tags. This is very similar to what you’re trying to achieve, but it’s only tested for my URL manager configuration:
private $canonicalUrl;
/**
* Prevent the display of a canonical URL, for instance on error pages.
*/
public function noCanonicalUrl()
{
$this->canonicalUrl = '';
}
/**
* Sets the canonical URL for the current page using the specified route and parameters.
*
* @param string the route in the form '/controllerId/actionId'.
* @param array() additional GET parameters.
*/
public function setCanonicalUrl($route, $params = array())
{
$this->canonicalUrl = 'http://'
. Yii::app()->params['canonicalDomain']
. $this->createUrl($route, $params);
}
/**
* Gets the canonical URL for the current page. If this has not been explicitly set, it
* will be generated from the current controller and action IDs. It uses the http
* protocol and the canonicalDomain configuration parameter.
*
* @return string the canonical URL.
*/
public function getCanonicalUrl()
{
if ($this->canonicalUrl !== null)
return $this->canonicalUrl;
return 'http://'
. Yii::app()->params['canonicalDomain']
. $this->createUrl($this->id . '/' . $this->action->id);
}