SEO
A 301 redirect map, one row per URL
A 301 redirect map is an old→new table with one row per URL and one target. Chains and 404 destinations show up in a script before Google finds them.
Key points
- 301 and 308 are both permanent: a 308 keeps the HTTP method, a 301 does not, and Google treats them alike.
- A healthy map has one row per old URL and always points to a destination that answers 200.
- The browser stores a 301: a wrong redirect is hard to undo for anyone who already visited the page.
A 301 redirect map is a table with one row per old URL and one final destination. When a row points to another row, the chain loses signals and time: the map is checked with a script, not by eye.
Where the rows come from
Rows are not invented: they come from three verifiable sources. The 404 report in Search Console says which URLs Google tried to read; the server access log says which URLs people requested; the old sitemap says which URLs really existed. The first command extracts the most requested paths that answer 404 today.
awk '$9 == "404" {print $7}' access.log | sed 's/?" HTTP.*//' | sort | uniq -c | sort -rn | head -n 20 > missing.txt
wc -l missing.txt
The command reads field 7 of the combined log, which holds the requested path, keeps the rows with status 404, strips the query string and sorts by frequency. missing.txt keeps the twenty most requested broken paths: candidates for the map, not every 404 on the site. A path requested once can be ignored; one requested two hundred times is a broken external link.
One map, one destination
- One row per old URL: two rules for the same path make the result depend on server order.
- Final destination, not an intermediate one: if /a points to /b and /b points to /c, the map sends /a to /c.
- The destination answers 200: a redirect to a 404 is worse than no redirect.
- Permanent redirects only: 301 or 308. A 302 tells Google the old URL will return, and it stays in results.
Checking before deployment
while IFS=