Rails SEO 第一步: Robots.txt

紅寶鐵軌客
Join to follow...
Follow/Unfollow Writer: 紅寶鐵軌客
By following, you’ll receive notifications when this author publishes new articles.
Don't wait! Sign up to follow this writer.
WriterShelf is a privacy-oriented writing platform. Unleash the power of your voice. It's free!
Sign up. Join WriterShelf now! Already a member. Login to WriterShelf.
寫程式中、折磨中、享受中 ......
1.2K   0  
·
2017/04/10
·
2 mins read


有沒有辦法讓Google 關鍵字搜索找的到?

這是一個大問題,我把他分成幾篇來寫,算是我的紀錄,以下是我的做法,應該可以是一個好的參考,寫出來也歡迎大家提的建議,互相幫忙:

第一改:Robots.txt

先把Robots.txt在開發版關了:(如果有用Stage也要關了)

disable search access the development site, 可以參考 - https://gist.github.com/timcheadle/3761844
Robots.txt 的說明可以看一下這裡:http://www.robotstxt.org/

在第一個進入的主網頁Controller中加上:MainPagesController -
def robots
 robots = File.read(Rails.root + "config/robots.#{Rails.env}.txt")
render :text => robots, :layout => false, :content_type => "text/plain"
end

再把 public/robots.txt 搬到 config,並改名為 robots.development.txt 及 robots.production.txt

routes 當然要加一行,改一下,
...
get 'robots.txt' => 'main_pages#robots'

就可以把robots.development.txt改成不讓search找到,簡單來說就是加這兩行:

User-agent: *
Disallow: /

robots.production.txt要配合Sitemap,所以一般就要寫成:

Sitemap: https://www.你的網址.com/sitemap.xml.gz

第一改結束。 下一篇就是Sitemap了。

驗證改好的robots.txt對不對,就還是要回到SEO的好朋友:Google webmasters

還沒向它報到,快去,基本上就是要驗證你的網頁是你的,一般要等一下,或一天,你的網頁有可以認證了,關於Robots.txt的確認,可以在Google webmasters 的 search console 上找到 Robots.txt 測試工具,點一下,你就知道Google 找到沒有,對不對!

基本上,Robots.txt 就是用來跟搜尋引擎說哪些要可以被外面看到,那些不要,我的建議是,如果是一些機密的,要考慮寫不寫,寫上,可能就提供給黑客一個破解點,我的建議是,不寫,用程式鎖這些網頁才是對的。

 

下一篇:Rails SEO 第二步: 關於 sitemap


WriterShelf™ is a unique multiple pen name blogging and forum platform. Protect relationships and your privacy. Take your writing in new directions. ** Join WriterShelf**
WriterShelf™ is an open writing platform. The views, information and opinions in this article are those of the author.


Article info

This article is part of:
Categories:
Tags:
Date:
Published: 2017/04/10 - Updated: 2017/10/27
Total: 418 words


Share this article:
About the Author

很久以前就是個「寫程式的」,其實,什麼程式都不熟⋯⋯
就,這會一點點,那會一點點⋯⋯




Join the discussion now!
Don't wait! Sign up to join the discussion.
WriterShelf is a privacy-oriented writing platform. Unleash the power of your voice. It's free!
Sign up. Join WriterShelf now! Already a member. Login to WriterShelf.