Answer the question
In order to leave comments, you need to log in
How to make different robots for a site on Bitrix for aliases?
There is a site site1.ru and an alias - spb.site1.ru
I write in urlrewrite.php
array(
"CONDITION" => "#^/robots.txt#",
"RULE" => "",
"ID" => "",
"PATH" => "/robots.php",
),
<?
define("NO_KEEP_STATISTIC", true);
define("NOT_CHECK_PERMISSIONS", true);
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
$arHost = explode( ":", $_SERVER["HTTP_HOST"]);
$_SERVER["HTTP_HOST"] = $arHost[0];
$hostname = isSubdomain($_SERVER['HTTP_HOST']);
function isSubdomain($host)
{
$host = str_replace("www.", "", $host);
str_replace(".", "", $host, $count);
if($count > 1)
{
$code = explode('.', $host);
return $code[0];
}
}
function echoTextFile($file) {
if (! file_exists($file)) return false;
if (! is_readable($file)) return false;
$timestamp = filemtime($file);
$tsstring = gmdate('D, d M Y H:i:s ', $timestamp) . 'GMT';
$etag = md5($file . $timestamp);
header('Content-Type: text/plain');
header('Content-Length: '.filesize($file));
header("Last-Modified: $tsstring");
header("ETag: \"{$etag}\"");
readfile($file);
return true;
}
$robotsHost = dirname(__FILE__) . "/robots/robots_{$hostname}.txt";
$robotsDefault = dirname(__FILE__) . "/robots/robots.txt";
if(!echoTextFile($robotsHost) && !echoTextFile($robotsDefault))
{
header('HTTP/1.0 404 Not Found');
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question