But turns out that the browser ignores our "custom" headers and doesn't send them in the new request. It makes sense, but how could I send the data I want to the /somewhere page? The solution is to either use cookies or query strings.
With cookies
If the cookie is already set, you don't need to do anything since the page will be able to read it as usual. But turns out you can also define them in the headers of the redirect, so this will still work:
TL;DR: you can't. You have to use cookies or query strings instead.
When I need to redirect the user to another page I often code it like this:
And I had a case where I needed to send some headers with the redirect, so I thought this could work:
But turns out that the browser ignores our "custom" headers and doesn't send them in the new request. It makes sense, but how could I send the data I want to the
/somewhere
page? The solution is to either use cookies or query strings.With cookies
If the cookie is already set, you don't need to do anything since the page will be able to read it as usual. But turns out you can also define them in the headers of the redirect, so this will still work:
Depending on what you doing you could delete the cookie on
/somewhere
right after reading it.With query strings
A simpler solution is to use query strings. You can send the value directly in the URL and it will work fine: