read the transcript!
Sometimes you type a URL into your browser:
but end up at a slightly different URL:
ooh, where did the cat come from? I didn’t type that!
Here’s what’s going on behind the scenes:
GET /dog.png HTTP/1.1 Host: examplecat.com
301 Moved Permanently Location: /cat.png
browser: okay, I’ll try
GET /cat.png HTTP/1.1 Host: examplecat.com
200 OK <rest of website here>
The Location header tells the browser what new URL to use.
The new URL doesn’t have to be on the same domain: examplecat.com/panda can redirect to pandas.com. Setting up redirects is a great thing to do if you move your site to a new domain!
! Warning !
301 Moved Permanently redirects are PERMANENT: after a browser sees one once, it’ll always use
examplecat.com/cat.png when someone types
examplecat.com/dog.png forever. You can’t take it back and decide to not to redirect. If you’re not sure you want to redirect your site for eternity, use
302 Found to redirect instead.