1

我正在使用 WordPress。其中一个文件functions.php包含function do_robots() {...阻止 Google 抓取的内容。我已将此功能替换为以下内容:

function do_robots() {
    header( 'Content-Type: text/plain; charset=utf-8' );

    do_action( 'do_robotstxt' );

    if ( '0' == get_option( 'blog_public' ) ) {
                     echo  "User-agent: *";
                     echo  "\nDisallow: /wp-admin";
                     echo  "\nDisallow: /wp-includes";
                     echo  "\nDisallow: /wp-content";
                     echo  "\nDisallow: /stylesheets";
                     echo  "\nDisallow: /_db_backups";
                     echo  "\nDisallow: /cgi";
                     echo  "\nDisallow: /store";
                     echo  "\nDisallow: /wp-includes\n";
    } else {
                     echo  "User-agent: *";
                     echo  "\nDisallow: /wp-admin";
                     echo  "\nDisallow: /wp-includes";
                     echo  "\nDisallow: /wp-content";
                     echo  "\nDisallow: /stylesheets";
                     echo  "\nDisallow: /_db_backups";
                     echo  "\nDisallow: /cgi";
                     echo  "\nDisallow: /store";
                     echo  "\nDisallow: /wp-includes\n";
    }
}
  1. 我不太确定Allow。是不是只要我不Disallow,就Allow默认了?
  2. 为什么 Google Bot 仍然被上述内容阻止function
4

1 回答 1

1

SVN的原始功能看起来比您上面的示例阻止的路径更少,因此我建议删除一些额外的目录(例如 wp-content)并查看是否是您要查找的内容。您还可以尝试使用 WordPress插件生成 Google 站点地图供其引擎读取。

function do_robots() {
    header( 'Content-Type: text/plain; charset=utf-8' );

    do_action( 'do_robotstxt' );

    $output = "User-agent: *\n";
    $public = get_option( 'blog_public' );
    if ( '0' == $public ) {
        $output .= "Disallow: /\n";
    } else {
        $site_url = parse_url( site_url() );
        $path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : '';
        $output .= "Disallow: $path/wp-admin/\n";
        $output .= "Disallow: $path/wp-includes/\n";
    }

    echo apply_filters('robots_txt', $output, $public);
}

文件的规则robots.txt是除非指定,否则一切都是允许的,尽管服从的搜索引擎robots.txt更像是一个信任系统而不是任何东西。

于 2013-05-18T03:44:16.503 回答