A
A
Al fox2020-05-03 19:32:46
PHP
Al fox, 2020-05-03 19:32:46

How to generate robots.txt for all subdomains with a new host?

I am moving to a new domain.
Now .htaccess looks like this:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^((?:[^.]+\.)*)domain1.ru$ [NC]
RewriteRule "" https://%1domain2.ru%{REQUEST_URI} [R=301]


For search engines, you need to give robots.txt with a new host. How to make it so that when requesting robots.tx of the old domain (and third-level domains), a file with the host of the new domain (or the corresponding third-level domain) is given?

Example:
https://domain1.ru/robots.txt -> in the file HOST was displayed: https://domain2.ru
https://omsk.domain1.ru/robots.txt -> HOST was displayed in the file: https://omsk.domain2.ru
https://tomsk.domain1.ru/robots .txt -> HOST was displayed in the file: https://tomsk.domain2.ru

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2020-05-03
@AleBas

Yandex has long abandoned the Host directive.
https://yandex.ru/blog/platon/pereezd-sayta-after-...

D
Daria Motorina, 2020-05-03
@glaphire

Write a rule in the server configs so that the robots.txt request is redirected to the generate_robots_file.php handler. In it, generate the content of the file based on the subdomain and return the content with the header "Content-Type: text/plain".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question