when you move or rename a page, the old link stops working. add a file called _redirects to the top of your site folder and the old address sends people to the new one instead of showing a missing page. search engines pass the old page's ranking on to the new one when you do this, and lose it when you don't.
the format is the same one netlify and cloudflare pages use, so examples you find elsewhere work here.
the file
make a plain text file named _redirects, with no extension, in your site's top folder. one rule per line:
# comments start with a hash
/old-page /new-page
/about-me /about 301
/docs/* https://docs.example.com/:splat
/news/:year/:slug /blog/:year/:slug
/discontinued - 410each line is: the old address, the new one, and an optional status code.
rules
- leave the status out and it is a 301, a permanent move. that is what you want almost always
302says temporary, so search engines keep the old address.410says the page is gone for good and takes-instead of a target- the first line that matches wins, so put specific lines above general ones
*at the end matches the rest of the address, and:splatputs it into the target:namematches one part of the address and:nameputs it into the target- anything after a
?in the visitor's link is carried across - the target is either a path on your site starting with
/, or a fullhttps://address somewhere else - up to 1000 rules
a page that still exists
a real page always wins over a rule, so a mistake in this file can never take one of your pages off your site. if you do want the redirect to win, put a ! after the status:
/old-home /home 301!moving a whole section away
two lines move a section to another site and keep every link that pointed at it:
/apps/notes-exporter https://exporter.dev/
/apps/notes-exporter/* https://exporter.dev/:splatsend each old page to the page that replaced it, not all of them to the new home page. a pile of redirects that all land on one home page is treated as a missing page by google and throws away the ranking you are trying to keep. and leave the rules in place: google keeps re-checking for months.
notes
- the file is only read from the top folder of your site, not from subfolders
_redirectsnever shows in your file list and cannot be opened on your site- a line with a mistake in it is skipped, and the rest of the file keeps working