admin管理员组文章数量:1130349
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 |2 Answers
Reset to default 3First 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;
}
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.txtover FTP? WordPress doesn't use it anyway. – user26607 Commented Feb 25, 2013 at 15:44
2 Answers
Reset to default 3First 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;
}
本文标签: configurationAdd robotstxt to root
版权声明:本文标题:configuration - Add robots.txt to root 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749163116a2325721.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


<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:36robots.txtover FTP? WordPress doesn't use it anyway. – user26607 Commented Feb 25, 2013 at 15:44