惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
爱范儿
爱范儿
量子位
Martin Fowler
Martin Fowler
V
V2EX
博客园 - 三生石上(FineUI控件)
I
InfoQ
MongoDB | Blog
MongoDB | Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
Netflix TechBlog - Medium
D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research
H
Help Net Security
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
Engineering at Meta
Engineering at Meta

Nic Lin's Blog

謝明真 - 高效領導力的課後筆記 NFT 開發實戰!基礎智能合約入門 (3) NFT 開發實戰!基礎智能合約入門 (2) NFT 開發實戰!基礎智能合約入門 (1) 如何自我檢測 log4j CVE 漏洞 Rails 如何在資料寫入時記錄來源 IP 位置 如何經營工程師 Youtube 頻道 - Part 8 營收篇 如何經營工程師 Youtube 頻道 - Part 7 酸民文化篇 如何經營工程師 Youtube 頻道 - Part 5 設備器材篇 如何經營工程師 Youtube 頻道 - Part 4 後製剪輯篇 如何經營工程師 Youtube 頻道 - Part 3 文案企劃篇 如何經營工程師 Youtube 頻道 - Part 2 設備器材篇 如何經營工程師 Youtube 頻道 - Part 1 制訂頻道方向篇 如何經營工程師 Youtube 頻道 - Part 0 Rails 中避免 race condition 的最佳實踐(二) Rails 中避免 race condition 的最佳實踐(一) 10 分鐘整合 google sheet 做自動化開發功能週報 經營 Side Project 300 天所帶來的收穫及挑戰 我的 Youtube 影片製作流程 API 設計時必須注意的 HTTP header 底線問題 如何提升你的程式可讀性之實務技巧(三) 如何提升你的程式可讀性之實務技巧(二) 如何提升你的程式可讀性之實務技巧(一) Ruby 中使用 freeze 優化效能的時機 避免 React 中的 useEffect 無限 render 在 Rails 內輕量使用 Vue Component 的最佳實踐 如何在區域網路用 Docker 架設有 SSL 的 Gitlab 從被問到問人,那些我常問的面試問題 [Rails] 如何漂亮寫出可維護的 query (Maintainable Rails Query) 在已知長度情況下優化 slice 的性能
[Rails] 禁止非 Production 環境下被搜尋引擎建立索引,提升...
Nic Lin · 2018-08-05 · via Nic Lin's Blog

除了把關鍵字的 SEO 做好以外,也要注意被「禁止收錄」的部分,有時我們會有其他的環境,例如 staging, 用不同的域名或是 subdomain 下去做等等,在這些情況下,不要讓搜尋引擎收錄網頁其實是有好處的,如果一個網站被收錄了很多對搜尋結果沒有幫助的網頁,反而會讓搜尋引擎認為網站內容空洞,導致網站的權重下降,所以排除這些不重要頁面也是 SEO 中的一個有用的方向。

如何查詢網站是否被收錄

  1. 以 google 來說,可以用 site:yourapp.com 來搜尋,可以查詢不想要被收錄的部分是否已經建立索引了。
  2. 查看 search console 的索引狀態,可以看一下有沒有被過度收錄的情況。

排除收錄的方法

因為不同的搜尋引擎可能會有不同的參考標的,所以盡量就是做到全面。

主要是兩招

  1. <meta> noindex 標籤
  2. robots.txt 檔案

先建立一個 helper

# app/helpers/application_helper.rb
  def render_ban_spider_from_crawling_meta_tag
    tag(:meta, { name: "robots", content: "noindex, nofollow" })
  end

在 view layout 中的

內都加上

<%= render_ban_spider_from_crawling_meta_tag unless Rails.env.production? %>

可以解絕大多數問題,操作也不難,缺點大概就是要單頁設定,如果 layout 很多就會有執行困難,但 Rails 中應該是還好。

robots.txt

把 public 中的 robots.txt 先搬過去 config/ 下 然後製作所有環境的 config/robots.environment.txt

$ mv public/robots.txt config/robots.production.txt
$ cp config/robots.production.txt config/robots.development.txt
def robots                                                                                                                                      
  robots = File.read(Rails.root + "config/robots.#{Rails.env}.txt")
  render text: robots, layout: false, content_type: "text/plain"
end
# routes.rb

get "/robots.txt" => "home#robots"

開發、staging 模式下, Disallow 所有

# robots.development.txt
# (moved from public/robots.txt)
#
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
User-Agent: *
Disallow: /

Production 預設是沒有設定,這裡可以自行設定

# robots.production.txt
# (moved from public/robots.txt)
#
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
# User-Agent: *
# Disallow: /

部屬後過陣子應該就會更新索引了

參考資源