$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>configuration - Add robots.txt to root|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

configuration - Add robots.txt to root

matteradmin7PV0评论

I have a new Wordpress 3.5.1 install (hosted on Dreamhost FWIW) that I do not want to be indexed by search engines. I would like to serve a simple robots.txt with Disallow: / for all user agents.

I have checked the "Discourage search engines from indexing this site" box on the Settings > Reading menu, but .txt still returns a 404.

Is there a way to have Wordpress automatically generate and serve an appropriate robots.txt file? If not, what is the best way to configure it to serve my own static robots.txt file?

I have a new Wordpress 3.5.1 install (hosted on Dreamhost FWIW) that I do not want to be indexed by search engines. I would like to serve a simple robots.txt with Disallow: / for all user agents.

I have checked the "Discourage search engines from indexing this site" box on the Settings > Reading menu, but http://mysite/robots.txt still returns a 404.

Is there a way to have Wordpress automatically generate and serve an appropriate robots.txt file? If not, what is the best way to configure it to serve my own static robots.txt file?

Share Improve this question asked Feb 25, 2013 at 15:34 Mike DeckMike Deck 1171 silver badge8 bronze badges 2
  • I just realized that the "Discourage search engines from indexing this site" setting adds a <meta content="noindex,nofollow" name="robots"> to the head section of each page which should accomplish my goal. I'd still like to know how to add a robots.txt too though. – Mike Deck Commented Feb 25, 2013 at 15:36
  • Can't you just manually upload a robots.txt over FTP? WordPress doesn't use it anyway. – user26607 Commented Feb 25, 2013 at 15:44
Add a comment  | 

2 Answers 2

Reset to default 3

First of all, in order for Wordpress to generate a robots.txt for you you must be using a non-default permalink structure. Make sure you've selected an option in the Settings > Permalinks menu.

Also, if a robots.txt file exists at your root directory it will override the setting in Wordpress. It looks like you already have a robots.txt file and that is the reason the wordpress setting is ignored.

You don't need to add robots.txt file to the root of your site. robots.txt file is generated in real time, when you visit http://mysite/robots.txt. The function, responsible for creation of this file, is do_robots.

If you wish to add your own directives, just write your hook for robots_txt filter, like this:

add_filter( 'robots_txt', 'wpse8170_my_robots_txt', 10, 2 );
function wpse8170_my_robots_txt( $output, $public ) {
    if ( '0' != $public ) {
        $output .= '
Disallow: /wp-content/plugins
Disallow: /wp-content/cache
Disallow: /wp-content/themes
';
    }
    return $output;
}

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far