Consider StackOverflow, where each question has a unique ID, but URLs are often overridden to include a stub in the URL. For readability and other reasons the stub helps users know they are at the right place.
I have a site that returns 200 when calling a URL like:
http://stackoverflow.com/questions/28057406/
But want the URL to update to:
http://stackoverflow.com/questions/28057406/is-it-possible-to-return-http-code-200-but-give-a-better-url-without-using-3x
The first call is technically valid and the code can retrieve the object and render it perfectly fine, but I'd like to update the URL to use the stubified one.
I'd prefer to do this without a redirect as just getting the ID causes a database call to get the object. Which would mean with a redirect the process would be:
- Call
http://stackoverflow.com/questions/28057406/
- Retrieve item
25257999
from the database to get the name to make the stub - Redirect to
http://stackoverflow.com/questions/28057406/is-it-possible-to-return-http-code-200-but-give-a-better-url-without-using-3x
- New HTTP Call, so retrieve item
25257999
from the database to render the final page.
If possible I'd like to not use Javascript either.
So, is it possible to return Location
as part of a HTTP header with a status code of 200
and the actual page, or am I stuck using 3xx
calls or Javascript?