I’ve recently re-built this personal site using Astro (yes, the web framework—not the dog from The Jetsons), and I wanted some different routes to display the same page. The mighty Astro docs told me there are two magical ways to do it: URL Redirects and URL Rewrites. This article briefly talks about the differences between these two approaches.
“URL redirection” (also known as “URL forwarding”), is a way to assign multiple URLs to a page, or to put in another way, to send users and sometimes search engines to a different URL than the one initially intended. It is simply the digital equivalent of saying, “Sorry, the content you’re looking for moved to a new address.”
https://www.yagmurcetintas.com/ and yagmurcetintas.com, because not everyone likes typing as much as I do.Redirections happen with HTTP status codes, and they can be temporary or permanent:
<meta> tags or JS (using window.location)Location header (URL2). This is just to inform the client that the resource it is looking for is no longer in the URL it sent, but there’s a new URL that contains the requested material.The HTTP code the client receives in step 2 is important because it tells the client if it should cache the new redirection location. For temporary redirection codes, the location is not cached unless stated otherwise with the relevant Cache-Control headers, meaning all requests to the old location will follow through the same flow explained above. Permanent redirections will be cached so the client browsers/search engine robots/RSS readers/proxy servers/any other crawlers know not to request the old location information anymore.
Server-side redirects are the most reliable way of doing redirections, but there are times when you don’t have access to the servers. At this point you can use the HTML redirections (meta tag) or JS redirections (window.location property). According to MDN web docs, HTTP redirects are executed first, JS redirects are executed second, and HTML redirects execute last. Usage of HTML redirects (meta tags) for redirections are discouraged since the gold standard is the HTTP redirections and if used together (mainly because of forgotten meta tags) it could lead to hard-to-debug nightmares of infinite loops.

URL rewriting is the sneakier cousin of URL redirection. It is the process of changing a URL behind the scenes—without changing the URL in the browser’s address bar. Unlike URL redirection which is totally visible on the client side and on the address bar of the browser, a URL rewrite is invisible to the user. Basically the user asks for a specific URL, browser serves another one, and the URL in the address bar never changes.
?id=234545 into something a human might actually want to click on, like /products/hairbrush/internal/api/987) from users, because exposing your API endpoints is like leaving your diary on the kitchen table during a house party