S
S
Sergey Pozdnyakov2019-01-13 18:08:54
1C-Bitrix
Sergey Pozdnyakov, 2019-01-13 18:08:54

How to make dynamic robots.txt for subdomains in Bitrix?

There is a site with subdomains, dynamic content from the region selection. I don’t understand how to make robots.txt correct for a subdomain.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
igorux, 2019-01-13
@igorux

If the directives in these files are the same, then they (the files) will differ only in the sitemap.xml address. Enable .htaccess to process txt as php and form a string with the sitemap.xml address using the HTTP_HOST variable.

V
Viktor Taran, 2019-01-13
@shambler81

1. if this is a multi-site then put it in each site
2. if it's just domain aliases, then the easiest way to do this is in nginx
3. as far as I understand, aspronet has something similar, then redo it yourself

robots.php
<?
$arHost = explode( ":", $_SERVER["HTTP_HOST"]);
$_SERVER["HTTP_HOST"] = $arHost[0];
$hostname = $_SERVER['HTTP_HOST'];
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__) . "/aspro_regions/robots/robots_{$hostname}.txt";
$robotsDefault = dirname(__FILE__) . "/robots.txt";
if(!echoTextFile($robotsHost) && !echoTextFile($robotsDefault))
{
header('HTTP/1.0 404 Not Found');
}

A
Alexey Bespalov, 2019-01-14
@FreeArcher

We are using this module.
https://marketplace.1c-bitrix.ru/solutions/webfly....
There, on the installation tab, there is an instruction on how to set up htaccess, but we have a redirect configured in nginx, set up a hoster.
It will be necessary to throw off how it's done.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question