Which redirect code to use for resolve resource?
On my website i have a list of items, each item has a link, the link has one parameter named "ID":
<a href="go?id=2">item</a>
When i generate the list i don't know the exact url to the item, for example it could be too expensive (lots of queries to all kind of resources) to figure out.
When to user clicks the link "go?id=2" the server figures out the exact url and sends the user to that url with a redirect code 301. This will always be the same url.
I was wondering if i'm using the correct http code for my case? Mainly because while doing research i discovered more redirect codes than the usual 301 and 302.
To answer your specific query, if this needs to be a redirect, then a 301 (permanent) is the correct one. It is always a GET request and it is permanent. The client will likely cache the 301 redirect, so will not query your site the next time.
However, as @Stephen mentioned in comments, you should ideally link to the target URL if at all possible.
At least cache the result of id=2
so that you can use the actual URL when the list of items is next generated. Or pre-compute these in the background at some point?
Comments
Post a Comment