This article is a continuation of multisite cases on WordPress. Here is an example of replacing the standard robots.txt with a multisite one.
1. If robots.txt file has already been created, rename it or delete it.
2. In .htaccess add the line:
RewriteRule ^robots.txt$ robots.php
3. Create a robots.php file with the following content:
<?php
header('Content-Type: text/plain; charset=utf-8');
echo 'User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
';
if($_SERVER['HTTP_HOST']=='subdomain1.domain.com'){
echo 'Host: https://subdomain1.domain.com
Sitemap: https://subdomain1.domain.com/sitemap_index.xml';
}
else if($_SERVER['HTTP_HOST']=='subdomain2.domain.com'){
echo 'Host: https://subdomain2.domain.com
Sitemap: https://subdomain2.domain.com/sitemap_index.xml';
}
else {
echo 'Host: https://domain.com
Sitemap: https://domain.com/sitemap_index.xml';
}
?>
Insert all the main content into the first echo, the rest of the dynamic will be placed according to the conditions with the host check.
WEBinP Your guide to resolving CMS optimization, Web Development and SEO problems