Monday , February 3 2025

If the link contains another domain/subdomain

The task is relevant if hosting subdomains refer to the root of the main site, or if several domains are registered as aliases to each other.

If you need to write noindex/nofollow etc., you can simply write a condition in index/header section:

<?php
$host = $_SERVER['HTTP_HOST']; 
 if($host == "old.domain.com" or $host == "www.old.domain.com") {
     echo 'meta name="robots" content="noindex, nofollow"';
 }
?>

Instead of old.domain.com and meta name=”robots” content=”noindex, nofollow” use your actual values.

About iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

Check Also

How to add 301 redirect to https for Yii2 without .htaccess

I’ve tested different redirect options for .htaccess, but sites keep giving “redirected you too many …

Leave a Reply

Your email address will not be published. Required fields are marked *