Guide
Geo-redirect visitors by country
Route visitors to a regional site, language, or pricing page based on the country of their IP address.
1. Look up the visitor's IP from your server
Read the visitor's IP from the incoming request and ask the API for its country. Keep your key on the server.
// Node/Express
app.get("/", async (req, res) => {
const ip = req.headers["x-forwarded-for"]?.split(",")[0] || req.socket.remoteAddress;
const r = await fetch("https://ipquery.info/api?ip=" + ip, {
headers: { Authorization: "Bearer YOUR_API_KEY" }
});
const country = (await r.json())[0]?.country_iso_code;
const map = { GB: "/uk", DE: "/de", US: "/us" };
res.redirect(map[country] || "/us");
});
2. Read country_iso_code
The response is an array with one object per IP. Use country_iso_code (ISO 3166-1 alpha-2, e.g. GB) for routing; continent and is_eu_member are handy for coarser rules.
3. Cache to protect your quota
Cache the result per IP (or per /24) for a few hours so repeat visits don't spend additional requests. Bulk lookups cost one request per address, so single look-ups are best for per-visitor routing.
See the full field reference for everything you can route on.