lundi 27 août 2018

How to redirect to new url, passing on old url, without session or query-string

The main key-feature I want here is the you were redirected from "old-url.html"

Check at what Wikipedia does when taking me to a canonical url of an article (which is exactly what I want to do):

enter image description here

Notice in the screenshot that I accessed old-url.html (united states of america article) but I was redirected to new-url.html (united states article), however, they didn't use any method for redirecting that I know of.

There are 3 main ways that I know how to redirect from old-url.html to new-url.html and let new-url-html know what was the old-url.html:

  1. store the old url in session, then redirect to new-url.html and there (with php for example) check if $_SESSION["redirected-from"] exists
  2. redirect to new-url.html?redirected-from=old-url.html (but with an ugly url)
  3. just update the document.title property and perhaps make a window.history.replaceState(...) to make it look like I redirected the request.

But none of those solutions look like what wikipedia did right there. Now, I can continue to try to hack my way through this requirement, or... I could ask the internet about perhaps a common http pattern that I could be unaware of...

Thanks in advance for your help :-)

Aucun commentaire:

Enregistrer un commentaire