タイトル: Incorrect namespace. Your Sitemap or Sitemap index file does
SEOタイトル: XML サイトマップ「Incorrect namespace」エラーの原因と対処
| この記事の要点 |
|
エラー全文と発生場所
Google Search Console → サイトマップ → エラー詳細
[エラーメッセージ]
Incorrect namespace.
Your Sitemap or Sitemap index file does not properly declare the namespace.
[該当ファイル]
https://example.com/sitemap.xml
[影響]
- 検索エンジンがサイトマップを処理できない
- 含まれる URL が新規発見対象から外れる
- 既存インデックス済 URL の更新検知が遅れる可能性
原因 1: xmlns 属性が間違っている
最頻出原因。xmlns の値は厳密に指定する必要があります:
原因 2: urlset と sitemapindex の混同
| ファイル種別 | ルート要素 | 子要素 |
|---|---|---|
| 個別サイトマップ | | / |
| サイトマップインデックス | | / |
https://example.com/sitemap-1.xml
https://example.com/sitemap-1.xml
https://example.com/page1
https://example.com/page1
原因 3: XML 宣言が無い
...
...
厳密には XML 宣言が無くてもパーサは動きますが、encoding が UTF-8 でない判定になるとエラー報告されます。必ず付ける習慣を。
原因 4: BOM 付き UTF-8 で保存している
Windows のメモ帳や一部エディタは UTF-8 ファイルの先頭に BOM (Byte Order Mark, EF BB BF の 3 バイト) を付けます。XML 宣言より前にバイトがあると、パーサが名前空間を含む先頭部分を正しく読めません:
# BOM の有無を確認
hexdump -C sitemap.xml | head -1
# 00000000 ef bb bf 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e |...
Visual Studio Code は右下にエンコーディング表示があるので、UTF-8 without BOM で保存しなおせます。
原因 5: CDATA を不要な箇所で使用
https://example.com/
https://example.com/page?id=1&type=a
原因 6: 不要な追加 xmlns で名前空間が混乱
...
https://example.com/photo.jpg
https://example.com/photo.jpg
デバッグの手順
- ブラウザで直接開く:
view-source:プレフィックスで XML 整形表示 - xmllint で構文チェック:
# Linux / Mac
xmllint --noout sitemap.xml
# OK なら何も出ない
# NG なら行番号付きエラー
# Schema 検証 (公式 XSD と照合)
curl -s -o sitemap.xsd https://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd
curl -s -o siteindex.xsd https://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd
xmllint --schema sitemap.xsd sitemap.xml --noout
xmllint --schema siteindex.xsd sitemap_index.xml --noout
- オンラインバリデータ:
- https://www.xml-sitemaps.com/validate-xml-sitemap.html
- https://www.websiteplanet.com/webtools/sitemap-validator/
- curl で生バイト確認:
# サーバから取得して BOM の有無を確認
curl -s https://example.com/sitemap.xml | hexdump -C | head -3
# Content-Type が text/xml か application/xml になっているか確認
curl -I https://example.com/sitemap.xml
# Content-Type: application/xml; charset=utf-8 ← 推奨
# サーバが gzip を返している場合
curl -H "Accept-Encoding: gzip" -I https://example.com/sitemap.xml.gz
サーバ側 Content-Type 設定
# Apache (.htaccess または httpd.conf)
AddType application/xml .xml
AddType application/xml .xml.gz
AddEncoding gzip .gz# Nginx (server ブロック)
location ~* \.xml$ {
add_header Content-Type "application/xml; charset=utf-8";
}
location ~* \.xml\.gz$ {
add_header Content-Encoding "gzip";
add_header Content-Type "application/xml; charset=utf-8";
}
修正後の再送信
- 修正したサイトマップをサーバにアップ
- キャッシュ削除 (CDN / Cloudflare Cache Purge)
- ブラウザで直接アクセスし、表示が正しいか確認
- Google Search Console → サイトマップ → 該当 URL の三点メニュー → 再送信
- または既存登録を削除 → 新規追加で再送
- 数時間〜数日で「成功」ステータスに変わるか確認
正しいサイトマップ例 (テンプレ)
https://example.com/
2026-06-10
daily
1.0
https://example.com/about
2026-05-15
monthly
0.5
https://example.com/sitemap-pages.xml
2026-06-10T09:00:00+09:00
https://example.com/sitemap-articles.xml
2026-06-10T09:00:00+09:00
FAQ
Q: 何度修正しても同じエラーが消えない
A: CDN や Cloudflare のキャッシュが古い XML を返している可能性。Cache Purge してから再送信。
Q: http:// と https:// の名前空間どちらが正しい?
A: 正式仕様は http://www.sitemaps.org/schemas/sitemap/0.9 (httpで)。Google は両方受理しますが、互換性のため http 版が安全。
Q: 自動生成プラグインの出力が NG だった
A: プラグイン側のバグ。最新版にアップデートするか、競合プラグインの干渉を疑う (Yoast と All in One が両方有効など)。