Here's a preview from my zine, HTTP: Learn your browser's language!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!
read the transcript!
Sometimes you type a URL into your browser:
examplecat.com/dog.png
but end up at a slightly different URL:
examplecat.com/cat.png
ooh, where did the cat come from? I didn’t type that!
Here’s what’s going on behind the scenes:
browser:
GET /dog.png
HTTP/1.1 Host: examplecat.com
server:
301 Moved Permanently
Location: /cat.png
browser: okay, I’ll try /cat.png
instead
browser:
GET /cat.png HTTP/1.1
Host: examplecat.com
server:
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.
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!