[架站] 為什麼網站的根目錄最好有 favicon.ico 和 robots.txt 存在?

o 如果已經在頁面的 <head> 中寫了 <link rel=”shortcut icon” href=”http://example.com/myicon.ico” /> 是否就不用在網站的根目錄中多弄一個 favicon.ico ?

o 如果所有頁面內容都不限制搜尋引擎的 bots 抓取,是否就不用在網站的根目錄中多弄一個 robots.txt ?

這一篇的結論是:還是讓它們存在網站的根目錄比較好。

網站的根目錄最好有 favicon.ico 和 robots.txt 存在其主要的原因是:有些瀏覽器還是會嘗試去存取網站根目錄的 favicon.ico;搜尋引擎的 bots 就是會去一直檢查網站根目錄是否有 robots.txt,所以最好這兩個檔案都存在,以避免你的網頁伺服器,例如: Apache web server,寫了一堆的「File does not exist: …./favicon.ico」或「File does not exist: …./robots.txt」到 error_log 檔案中,浪費儲存空間和伺服器資源。

o Favorites Icon 最好在網站的根目錄,並且名稱就是 favicon.ico

  • 雖然你可以在 <head> 中 用 <link rel=”shortcut icon” href=”http://example.com/myicon.ico” /> 之類的讓網站 icon 不一定要取名為 favicon.ico,也不一定要放在網站的根目錄,大部分的主流瀏覽器,如:Internet Explorer (IE)、Google Chrome、Firefox、Opera、Safari,也都能接受,但是為了避免有些不上道的瀏覽器存取網站根目錄的 favicon.ico,你最好: (1) 將網站 icon 取名為 favicon.ico 並且放在根目錄; (2) 在 <head> 寫成 <link rel=”shortcut icon” href=”http://example.com/favicon.ico” />。這樣相容性最高。
  • favicon.ico 的檔案格式最好是 ICON 格式,這樣相容性最高 (基本上 IE 只吃 ICON 格式的)。

ps: 如果你原本是將 Favorites Icon 在 <head> 中、如同上述例子中,指定到 myicon.ico,那在你接受上述建議改成網站的根目錄的 favicon.ico 以後,最好還是複製一份到 myicon.ico 或是將 favicon.ico 建立個 symbolic link 到 myicon.ico,以避免取得舊有資料的瀏覽器在還沒更新資料以前 (例如按 F5 按鍵重新載入) 一直去要存取 myicon.ico,這樣一來一樣會有一堆「File does not exist: …./myicon.ico」訊息寫到 error_log 檔案中 :p 。 建立 symbolic link 的命令列範例如下:

ln -s favicon.ico myicon.ico

o robots.txt 最好存在於網站的根目錄
與其弄一空的 robots.txt 檔案,你不如簡單地這樣寫兩行:

User-agent: *
Allow: /

o 那 apple-touch-icon 勒!?
對於 Apple 公司的 iOS 1.1.3 或之後版本的裝置:iPod Touch、iPhone 和 iPad,這些裝置可能會存取網站根目錄的 apple-touch-icon-72×72-precomposed.png、apple-touch-icon-72×72.png、apple-touch-icon-precomposed.png、apple-touch-icon.png 這幾個檔案,不存在的話一樣會有「File does not exist: …」訊息寫到 error_log 檔案去,例如:

[Tue Oct 25 20:09:00 2011] [error] [client 223.xxx.xxx.xxx] File does not exist:
/home/sites/www1/apple-touch-icon-72x72-precomposed.png
[Tue Oct 25 20:09:01 2011] [error] [client 223.xxx.xxx.xxx] File does not exist:
/home/sites/www1/apple-touch-icon-72x72.png
[Tue Oct 25 20:09:01 2011] [error] [client 223.xxx.xxx.xxx] File does not exist:
/home/sites/www1/apple-touch-icon-precomposed.png
[Tue Oct 25 20:09:04 2011] [error] [client 223.xxx.xxx.xxx] File does not exist:
/home/sites/www1/apple-touch-icon.png

所以,要是網站根目錄不存在這些檔案的話,最好在 <head> 中用以下語法交代一下它們在哪:

<link rel="apple-touch-icon" href="somepath/image.png" />
<link rel="apple-touch-icon-precomposed" href="somepath/image.png" />

3 thoughts on “[架站] 為什麼網站的根目錄最好有 favicon.ico 和 robots.txt 存在?”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.