With www or without?

Definition of the main mirror for Yandex.

In order for Yandex to glue both mirrors, he needs to specify the domain of the main site in the HOST directive.
For example, if you want to show that your primary domain is http://www.site.ru , then the robots.txt file will look like this:
User-agent: Yandex
Disallow:
Host: www.sitename.ru

User-agent: *
Disallow:
Sitemap: http://www.sitename.ru/sitemap.xml
User-agent: Yandex
Disallow:
Host: www.sitename.ru

User-agent: *
Disallow:
Sitemap: http://www.sitename.ru/sitemap.xml
HOST directive is intended exclusively for Yandex, so it is not superfluous to prescribe (duplicate) the necessary directives for the robots of other search engines.

Definition of the main mirror for Google.

To determine the main mirror for Google, do the following step-by-step:
1. Register the site in the Google Webmaster Tools service .
2. Having studied the instructions, confirm the rights to manage the site;
3. Select the following item in the menu "Site Configuration-> Settings-> Primary Domain" and tick the box next to the required domain.

Use of 301 redirects.

In order to show the search engines that your site is http://site.ru/ - the main site, write the following lines in the technical file .htaccess , located in the root directory of the site:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)(.*)$
RewriteRule ^(.*) http://%2/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^(site\.ru)$
RewriteRule ^(.*) http://site.ru/$1 [R=301,L]
RewriteRule ^robots.txt$ - [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)(.*)$
RewriteRule ^(.*) http://%2/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^(site\.ru)$
RewriteRule ^(.*) http://site.ru/$1 [R=301,L]
RewriteRule ^robots.txt$ - [L]
In order to show the search engines that your site is http://www.site.ru/ - the main site, write the following lines in the technical file .htaccess :
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site.ru
RewriteRule ^(.*)$ http://www.site.ru/$1 [R=301,L]