![[Hugo] GSCで“取得できませんでした”を解決するまで──sitemap.xmlがHTMLを返す罠](https://humanxai.info/images/uploads/hugo-search-console.webp)
はじめに
ブログ開設して記事も相当数たまりましたが、Goole Search Consoleにずっと登録してなかったので、 いまさらながら登録したのですが、思いのほかハマったのでメモも含めて記事にします。
pingを送る方法もあるようです。

Search Console使わずPingでGoogleインデックス登録を促す
Google Search Console登録しなくてもインデックス登録してもらえる? Pingを送ればOK? Google検索で結果としてサイトが表示されるには、Googleのクローラーにページを訪問してもらって、インデックス登録をしてもらう必要がある。そうでない限り、Google検索でサイトのページが検
https://hugo-de-blog.com/hugo-googleping/1. 現象と症状
Google Search Consoleで /sitemap.xml
を送信すると、ステータスが「取得できませんでした」のまま。
ブラウザでは問題なく開け、curl
でも HTTP/2 200
と content-type: application/xml
が返る。
ファイルサイズも正常(約260KB)。──なのに、GSCは拒否する。
❯ curl -I https://humanxai.info/sitemap.xml -H "User-Agent: Googlebot"
HTTP/2 200
content-type: application/xml; charset=utf-8
content-length: 266544
この時点では、サーバやキャッシュ、XML構造の問題を疑っていた。
2. 疑わしい原因を洗い出す
1. URLの整合性
sitemap.xml
内のURLを抽出し、ホストの一致を確認。
curl -s https://humanxai.info/sitemap.xml -H "User-Agent: Googlebot" \
| awk -F'[<>]' '/<loc>/{print $3}' \
| sed -E 's#^https?://([^/]+)/.*#\1#' \
| sort | uniq -c
結果:
1320 humanxai.info
→ 全URLが humanxai.info
に統一されており、ドメインの不整合はなし。
2. 相対URL・未エスケープ文字
&
の未エスケープや <loc>
の相対パスを確認。
結果はいずれも正常。
3. 多言語設定の影響
Hugoの defaultContentLanguageInSubdir = true
設定があるため、
/ja/sitemap.xml
が実体になっている可能性を確認。
ブラウザでアクセスしたところ──
トップページ(HTML)が表示された。
3. 原因の確定:SPAルールの巻き込み
Netlifyの _redirects
に記載されていたルール:
/admin/* /admin/index.html 200
/* /index.html 200
この /* /index.html 200
が最優先でマッチし、
sitemap.xml
や /ja/sitemap.xml
までもHTMLルーティングされていた。
4. 修正方法
_redirects
を以下の順序で書き換え、
sitemap.xml
と robots.txt
をSPA対象から除外。
/sitemap.xml /sitemap.xml 200
/ja/sitemap.xml /ja/sitemap.xml 200
/robots.txt /robots.txt 200
/ja/robots.txt /ja/robots.txt 200
/admin/* /admin/index.html 200
/* /index.html 200
再デプロイ後:
https://humanxai.info/sitemap.xml
→ XMLが直接表示https://humanxai.info/ja/sitemap.xml
→ XMLが直接表示curl -I
でもapplication/xml
確認済み- GSC再送信 → 取得成功 ✅
5. 教訓
- SPA構成では、sitemap.xmlとrobots.txtの明示除外が必須。
curl
で200でも、実体がHTMLならGSCは弾く。- Hugo+Netlifyの多言語構成では、
/ja/
側のファイルも確認すべし。 - コメントと再現ログを残すことで、後から自分を助けられる。
公式/フォーラム情報
1. Hugo の公式フォーラム:Custom sitemap 設定
「Custom sitemap.xml」のトピックで、Hugo テンプレートや設定で sitemap をカスタマイズしようとしたがエラーになる、という議論。 Hello!We have been trying to set up the customized sitemap.xml. We’ve followed the instructions from https://gohugo.io/templates/sitemap-template/ but nothing seems to make it work. It always says that “error on line 2 at column 1: Document is empty” / “error on line 2 at column 6: XML declaration allowed only at the start of the document hugo”.The default .xml file (evoir.fi/sitemap.xml) is giving the urls only in “/”, “/blog” etc. but google doesn’t understand those and they should be set ...
(特に XML 宣言の位置、空白行、テンプレートの衝突など)
→ デフォルトの sitemap が生成されず、空ドキュメントになるケースも報告。
(HUGO)
Custom sitemap.xml
2. Hugo Issues:content/sitemap/ に folder を置くと不具合
Issue #12183:Hugo バージョン 0.123 系で、 content/ └── sitemap/ └── index.md <-- type = sitemap layouts/ ├── _default/ │ └── single.html └── sitemap/ └── single.html Expected (v0.122.0) public/ ├── sitemap/ │ └── index.html └── sitemap.xml...content/sitemap/
や layouts/sitemap/
フォルダを使ってカスタム sitemap ページを持つと、デフォルトの public/sitemap.xml
が生成されないバグ。
→ この報告では、Hugo 0.123.7 で修正されたとある。
(GitHub)
sitemap.xml not generated when content contains sitemap directory · Issue #12183 · gohugoio/hugo
また、この問題は Hugo フォーラム内の “Don’t name a folder ‘sitemap’” トピックでも扱われている。 I discovered to my surprise today that my Hugo site had no sitemap.xml file. I’ve long had folders named content/sitemap/ and layouts/sitemap/ for the purpose of generating an HTML sitemap, but never saw a problem with that until now regarding the standard, default XML sitemap that Hugo normally creates automatically. Lo and behold, once I renamed those two folders (to content/sitemaphtml/ and layouts/sitemaphtml/, respectively), Hugo once again happily generated sitemap.xml in the /public folde...
(HUGO)
Don’t name a folder “sitemap”
3. Hugo フォーラム:_redirects を Hugo が参照すべきか
“Hugo respects _redirects files: desirable feature?
” という議論があり、
Hugo の開発サーバー (hugo serve
) は _redirects
を無視する仕様で、Netlify 側がリダイレクトを処理する、という理解が示されている。
(HUGO)

Hugo respects _redirects files: desirable feature?
Netlify, Cloudflare and IPFS allow use of a _redirects file to direct their HTTP servers to send specific HTTP status codes and Location headers for paths that don’t exist in the static files they serve.I’d like to see Hugo’s local dev server respect these files, so as to better test how my sites will work when published. I’m willing to build/submit a PR for this feature, if it seems desirable, and the Hugo team deem it suitable of maintenance costs. Is this interesting to you?A sample file: ...
https://discourse.gohugo.io/t/hugo-respects-redirects-files-desirable-feature/49699?utm_source=chatgpt.comつまり、ローカルでリダイレクトが反映されないのは仕様範囲という見方。
4. Netlify フォーラム:Netlify + Hugo でリダイレクト問題
「Issues with Redirects」フォーラムで、Hugo + Netlify の _redirects
や netlify.toml
を使ったリダイレクトが期待通り動かない事例。
静的サイト生成時のファイル位置問題や、リダイレクトファイルの置き場所に関する議論あり。
(Netlify Support Forums)

Issues with Redirects
Hi all -I am running into a couple of issues with redirects that I have been struggling to resolve. No redirect seems to work using netlify dev.
https://answers.netlify.com/t/issues-with-redirects/4910?utm_source=chatgpt.comまた、Netlify 側で HTML観点では正しいが、Googlebot やリダイレクト解釈で HTML が返されてしまうという文脈も。
(Netlify Support Forums)

Redirects not working yet
Hi,I’ve read through posts here, tried a few things and could use some advice on getting redirects working for my Hugo project.Here’s what I know so far:Added a _redirects file to the /static directory for the site www.beeboxdesigns.com(I also tried redirects in netlify.toml)Contents of the _redirects file# example redirect /synthtalk/ios-midi-sequencers https://www.synthtalk.net/articles/ios-midi-sequencers /synthtalk/*https://www.synthtalk.net/:splat 301 Netlify...
https://answers.netlify.com/t/redirects-not-working-yet/12016?utm_source=chatgpt.com
💬 コメント