Atlaslog
Atlaslog / Field Notes / Tiles
Field note · Tiles

Tianditu tiles return 403 because the Referer is not whitelisted

Quick answer

Pasting the WMTS URL into the address bar displays the tile, but inside the map every request returns 403 with 'Invalid referer'. The key is valid; the browser's Referer (localhost or file://) is simply not in the console whitelist.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: Tianditu API 4.0 / Leaflet 1.9.x / Vite 5.4
Symptom
Checklist
  1. Read the actual `Referer` request header in dev tools
  2. Compare it character by character with the whitelisted domains, including port and `www`
  3. Test with `curl -H "Referer: https://example.com/"` against the full WMTS URL
  4. Check for a proxy or hosts rewrite that alters the Referer
  5. Test without a Referer header to see that the whitelist check is skipped
Fix

Add the dev origin to the key's whitelist, or proxy same-origin during development (`server.proxy['/tdt']` with `changeOrigin: true` and a path rewrite) and request `/tdt/vec_w/wmts?...&tk=...`; in production register the real domain instead of proxying.

Code
<html>
<head><title>403 Forbidden</title></head>
<body><h1>403 Forbidden</h1><p>Invalid referer</p></body>
</html>
# 带合法 Referer,应返回 200
curl -I -H "Referer: https://example.com/" ^
  "https://t0.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX=10&TILEROW=392&TILECOL=843&tk=你的key"

# 不带 Referer 也可能 200,容易被误判为 Key 没问题
curl -I "https://t0.tianditu.gov.cn/vec_w/wmts?..."
Watch out
All 120 field notesChinese originalRunnable examples
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Cite this page

Atlaslog (2026). Tianditu tiles return 403 because the Referer is not whitelisted. https://www.jingweizhi.com/en/cookbook/tile-403-referer.html (accessed 2026-11-03).