I need to replace all relative URL to absolute URL of a web page using only HTML DOM. It's possible?
I am also using yii2.
Example
<link href="/css/site.css" rel="stylesheet">
<a href="/page">Page</a>
Result:
<link href="http://www.example.com/css/site.css" rel="stylesheet">
<a href="http://www.example.com/page">Page</a>
set $scheme parameter to true to return an absolute url if you want to link to an controller action.
Url::to(['my_controller/action'], true);
http://www.yiiframework.com/doc-2.0/yii-helpers-baseurl.html#to()-detail
For files you can use this Html::a( $text, $url = null, $options = [] )
with below options
// A normal string. This will use the exact string as the href attribute
$url = 'images/logo.png'; // This returns href='images/logo.png'
// A string starting with a Yii2 alias
$url = '@web/images/logo.png' // This returns href='http://www.example.com/images/logo.png'