educative.io

Why we do a 302 redirect instead of 301 redirect

I was wondering why are we doing a 302 temporary redirect instead of 301 permanent redirect given that 301 is SEO friendly while 302 isn’t.

Are there any other reasons for doing this?

Hi, 301 means “moved permanently.” 302 simply means “found.”

Here we are not designing a permanent redirection service. We are designing a service that can generate shortURLs that can easily be shared. Customers wouldn’t want to tell the search engine crawler that their website as moved to some 3rd party shortURL service’s domain :slight_smile:

4 Likes

@systems is incorrect. Because the 301 is from the url shortener to the 3rd party url so it rather the Url Shortener that would be worried SEO wise but only barely.

The main reason for 302 is that, it means that the redirect is only temporary which means if your browser call the short url a second time, it is expected to reach the server and not be cached-redirect (will explain later) which will allow you to count every time the redirection was performed.

301 is temporary redirect, meaning that to save time certain router and certain browser won’t even hit the server again to try, they will just cache the response/instruction and redirect you directly.

With this, you can’t count anymore how many people were redirected, and even if a link has expired, the network (layers and layers of routers) will still redirect users for a while before that cache expires too.

It is not an either/or: you are both right.

We are not designing a permanent redirect because a constraint of the system is that URLs can expire. Thus, a permanent redirect would be inappropriate as an expired URL could hang around in the cache of a system lower on the network stack. I would argue this is the PRIMARY use-case only because we are adhering to an actual standard (RFC 7231).

Any telemetry we get access to as a result of a non-cacheable response by adhering to this standard is a byproduct.