Данный скрипт автоматически добавляет атрибут nofollow
ко внешним ссылкам на странице, тем самым сохраняя ссылочный вес, не передавая его внешним сайтам. Google и Яндекс все равно найдет эти страницы и проиндексирует, но не будет далее переходить по закрытым nofollow ссылкам.
function add_nofollow($text){
return preg_replace('/href="(http:\/\/.*?)"/','href="$1" rel="nofollow"',$text);
}
'components' => [
// ...
'view' => [
'on afterRender' => function ($e) {
$layoutPath = 'layouts/main';
if (strstr($e->viewFile, $layoutPath)) {
$skip = 'mydomain.ru';
$e->output = preg_replace_callback(
'/(<a[^>]+?)>/is', function ($match) use ($skip, $skip2) {
if (!($skip && strpos($match[1], $skip) !== false) &&
strpos($match[1], 'rel=') === false &&
strpos($match[1], 'http') !== false
) {
return $match[1] . ' rel="nofollow">';
}
return $match[0];
}, $e->output);
}
},
],
// ...
],