I
I
IgorRastarov2018-04-19 21:54:02
1C-Bitrix
IgorRastarov, 2018-04-19 21:54:02

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",
),

I drive robots.php to the root.
robots.txt - which I rename at the root.
I create a folder /robots/
there I put robots.txt
and for subdomain robots_spb.txt
php file
<?
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');
}

As a result, at spb.site1.ru/robots.txt - 404 not found. nginx
Could it be a problem with nginx?
What to do in such a situation?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question