robots.txt檔案的語法規範是什麼?

robots.txt檔案是一個文字檔案,用於向搜尋引擎的蜘蛛(或機器人)提供網站的訪問指導。以下是robots.txt檔案的語法規範:

  1. User-agent:指定應用這些規則的搜尋引擎蜘蛛或機器人的名稱。常見的蜘蛛包括”Googlebot“、”Bingbot“和”*”(適用於所有蜘蛛)。
  2. Disallow:指示搜尋引擎蜘蛛不應訪問的URL路徑。可以使用萬用字元 `*` 表示任意字元,例如 `/admin/*` 表示不允許訪問以 “/admin/” 開頭的所有路徑。
  3. Allow:指示搜尋引擎蜘蛛允許訪問的URL路徑。通常用於強調特定規則的例外情況。
  4. Sitemap:指定網站的XML sitemap檔案的位置。可以列出多個XML sitemap檔案。

以下是一個簡單的robots.txt檔案的示例:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
User-agent: *
Disallow: /admin/
Disallow: /private/
User-agent: Googlebot
Disallow: /temp/
Allow: /public/
Sitemap: https://www.example.com/sitemap.xml
User-agent: * Disallow: /admin/ Disallow: /private/ User-agent: Googlebot Disallow: /temp/ Allow: /public/ Sitemap: https://www.example.com/sitemap.xml
User-agent: *
Disallow: /admin/
Disallow: /private/

User-agent: Googlebot
Disallow: /temp/
Allow: /public/

Sitemap: https://www.example.com/sitemap.xml

在這個示例中,`User-agent` 規則指明瞭針對所有蜘蛛的規則,然後是特定的規則針對 `Googlebot` 。 `/admin/` 和 `/private/` 被禁止訪問,但 `/temp/` 在 `Googlebot` 中是禁止的,但允許在其他蜘蛛中訪問。最後,`Sitemap` 規則指定了網站的XML sitemap檔案的位置。

請注意,robots.txt檔案只是給搜尋引擎蜘蛛提供指導,而不是強制性的規則。遵循robots.txt的建議是搜尋引擎最佳實踐,但不保證所有搜尋引擎都會遵循這些規則。

未能解決您的問題?

請提交 聯絡工單