Featured image of post 静的サイトジェネレータHugoで作成したサイトにrobots.txtを追加する方法

静的サイトジェネレータHugoで作成したサイトにrobots.txtを追加する方法

これはなに Link to this heading

この記事では、静的サイトジェネレータHugoで作成されたサイトに、robots.txtファイルを追加する方法を紹介する。robots.txtは、ウェブサイトのクローリングを制御する重要なファイルである。

Hugoでデフォルトのrobots.txtを生成する方法 Link to this heading

Hugoでは、configファイルでenableRobotsTXTtrueにすると、自動でrobots.txtをpublic直下に生成してくれる。

config.yaml
enableRobotsTXT: true

利用しているテーマにrobots.txtのテンプレート1が含まれていない場合は、下記に示すシンプルなファイルが生成される。

/public/robots.txt
User-agent: *

robots.txtをカスタマイズする方法 Link to this heading

Hugoが生成するrobots.txtをカスタマイズするには、/layouts/robots.txtを作成し、そこにカスタム内容を書き込む。 たとえば、下記の内容を持つrobots.txtをlayouts下に生成する。

/layouts/robots.txt
User-agent: *
Disallow:
Sitemap: {{ "sitemap.xml" | absURL }}

その後hugoコマンドを実行すると、public直下にカスタマイズされたrobots.txtが生成される。

/public/robots.txt
User-agent: *
Disallow:
Sitemap: https://notes.nakurei.com/sitemap.xml

特定のクローラーに対するrobots.txtの設定例 Link to this heading

Googlebotに対する設定例 Link to this heading

User-agent: Googlebot
Disallow: /private/

他のウェブクローラに対する設定例 Link to this heading

User-agent: Bingbot
Disallow: /private/

robots.txtの設定ミスによる検索エンジンへの悪影響 Link to this heading

robots.txtの設定ミスは、サイトが検索エンジンで正しくインデックスされない原因となる。そのため、設定を変更する際は、特にDisallowやAllowの指定を正確に行うことが重要である。設定ミスを防ぐために、robots.txtを変更した後は、robots.txtの設定が正しく反映されているか確認しよう。確認には、Google Search Consoleで用意されているrobots.txtテスターや、Bing Webmaster Toolsに用意されているrobots.txtテスターを利用できる。

参考文献・URL Link to this heading

robots.txt template image

robots.txt template

gohugo.io favicon image gohugo.io
Hugo の robots.txt と Sitemap。 | ふうせん🎈 FU-SEN image

Hugo の robots.txt と Sitemap。 | ふうせん🎈 FU-SEN

balloon-jp.vercel.app favicon image balloon-jp.vercel.app
Inno Lab - Klikbet77 Museum Game Dengan Gudang Link Resmi Terbaru image

Inno Lab - Klikbet77 Museum Game Dengan Gudang Link Resmi Terbaru

Klikbet77 adalah pusat hiburan digital inovatif dengan koleksi game interaktif serta gudang link resmi terbaru yang cepat dan aman, didukung penuh oleh Inno Lab terpercaya.

open-groove.net favicon image open-groove.net


  1. /themes/<THEME>/layouts/robots.txt ↩︎

Licensed under CC BY-NC-SA 4.0
最終更新 8月 14, 2025
Hugo で構築されています。
テーマ StackJimmy によって設計されています。