链接到同一根文件夹的不同域名的robots.txt内容不同

问题描述 投票:0回答:2

我有两个域名链接到同一个根。如何让robots.txt根据域名有不同的内容?

dns robots.txt
2个回答
1
投票

编写您自己的服务器脚本(就像在 PHP 上一样)并将重定向添加到 .htaccess


0
投票

同一服务器上多个域的另一种方法

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 );
?>
© www.soinside.com 2019 - 2024. All rights reserved.