[英]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.