我有两个域名链接到同一个根。如何让robots.txt根据域名有不同的内容?
编写您自己的服务器脚本(就像在 PHP 上一样)并将重定向添加到 .htaccess
同一服务器上多个域的另一种方法
htaccess
#加载php文件 RewriteRule ^robots.txt$“/robots.php”[L]
php 文件 robots.php
<?php
header("Content-Type: text/plain");
// default path
$path = "./robots.txt";
if ( preg_match("/domainname_one/i",$_SERVER['SERVER_NAME']) ) {
$path = "./domainname_one_folder/robots.txt";
}
if ( preg_match("/domainname_two/i",$_SERVER['SERVER_NAME']) ) {
$path = "./domainname_two_folder/robots.txt";
}
if ( preg_match("/domainname_three/i",$_SERVER['SERVER_NAME']) ) {
$path = "./domainname_two_folder/robots.txt";
}
echo file_get_contents( $path );
?>