[英]In WordPress, is there a way to exclude a single directory from being indexed with the meta robots tag instead of single pages or posts?
我知道这会将meta robots标记应用于特定页面或帖子:
<?php if ($post->ID == X || $post->ID == Y) { echo '<meta name="robots"
content="noindex,follow">'; } ?>
但我想将相同的meta标记应用于包含70个文件的特定目录。 有什么办法可以在php中做到这一点? 我非常感谢您的回答。 太感谢了。
meta robots标签仅在网页上使用。 这些网页可以是post,也可以是wordpress中的页面。 现在,要隐藏目录以免建立索引,您需要使用其他方法。
首先,请确保您没有通过robots.txt文件禁止该目录。 然后,在目录中创建一个htaccess文件,并添加以下行以防止建立索引。
Header set X-Robots-Tag "noindex, nofollow"
现在来看,如果Google已经为其中的文件建立了索引,那么您应该转到网站站长工具,然后从那里的Google索引中删除这些网址。 上面的解决方案将适用于您采用此解决方案后创建的文件。 但是,我想让您在答案中阐明的一件事是目录中文件的类型? 如果您可以让我知道目录中文件的扩展名,那么我可以为您提供定制的解决方案。 例如,假设您有60个pdf文件和10个html文件,并且您只想隐藏pdf文件,那么对此也有解决方案。
否则,如果您的查询已解决,那就太好了。
robots.txt添加以下行: Disallow: /your/path/to/the/folder/that/should/not/be/indexed/
我不确定您拥有哪种页面,也可以通过wordpress或自定义php方法,使用array()
创建一个文件,其中包含不应索引的所有页面,并在if和else语句,例如,如果页面在您的数组中,则编写您的元标记,如果页面不在数组中,则执行其他操作或不执行任何操作。如果文件使用相同的文件加载页面,则文件应包含在页面中所有页面上的meta标签,您可以在其中添加它。
<?php
$nofollow = array('name1', 'name2', 'name3', 'name4');
$curr_ID = 'get the current page ID'; // write something that is able to put the current page ID here..
if (in_array($curr_ID, $nofollow))
{
echo '<meta name="robots" content="noindex,follow">'; // the page ID is in the array
}
else
{
echo '<!--// Do nothing or do something else //-->'; // The page ID is not in your array, do what you'd like to do here..
}
?>
这是您一直在寻找的东西吗?
500个被索引的页面很多页面,并且有不良结果,但是您可以在此处将它们完全从google索引中删除,如果文档中包含个人信息,也可以要求将其删除,请在Google上搜索有关此法律的信息: 欧洲法律:您有被遗忘的权利
关于noindex,nofollow,noarchive:
noindex是:禁止索引您的页面
nofollow是:禁止关注。
无存档是:不允许cashe在searchengines页面
下面的.htaccess答案也是可以的,但是正如Aman Kapoor在他的答案中所说的,不要将robots.txt和.htaccess都用于您想做的同一件事。 您只能使用一种方法。
.htaccess示例代码1:
<IfModule mod_headers.c>
# Header set X-Robots-Tag "noindex, nofollow, noarchive"
# this can be used to exclude the html extension, change html
# to an other extension if you need an other to exclude..
# Remove your-folder in the code below and use the htaccss file in the same folder,
# your-folder was added to explaine if there is something you would like to exclude in a folder inside the folder where you would like to exclude something, this is how you can do that...
<FilesMatch "^your-folder\.html$">
Header set X-Robots-Tag: "noindex, nofollow, noarchive"
</FilesMatch>
</IfModule>
以下使用.htaccess
的示例确实排除了与您添加的扩展名匹配的所有文件,示例2:
<IfModule mod_headers.c>
# Add more extensions if needed or remove the extensions you do not want to exclude! (jpe?g is both jpeg and jpg)
<FilesMatch "\.(php|htm?l|html|doc|pdf|png|jpe?g|gif)$">
Header set X-Robots-Tag "noindex, noarchive, nosnippet"
</FilesMatch>
# </IfModule>
我使用正确的.htaccess
代码更新了我的答案,以使用.htaccess
,它可以正常工作,但是您也可以使用服务器配置文件或robots.txt方法来停止对文件夹编制索引。
我想说的就是尝试一下最喜欢的方法,然后添加您的选择(robots.txt或.htaccess或服务器配置):别忘了转到Google网站站长工具并从索引中删除文档/文件和其他文件,此后,您将需要在webmastertools中为您的网站请求完整的网站索引。
.htaccess
示例,如果应从搜索索引中排除多个扩展名,如果您无权访问配置文件,则这是执行所需操作的最佳选择。 我相信您能做的最好的就是添加第二个htaccess示例(编辑扩展名以符合您的需求),转到webmastertools并从其索引中删除500个文档,然后请求一个完整的网站抓取/添加网站以在webmaster工具中再次建立索引
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.