PHP重定向而不保存历史记录

Good afternoon! The question arose. I'm using PHP. User goes to example.com/in/ and the script redirects to http://example.com/ (using header("Location: ...") ;). How to avoid saving example.com/in/ in the browser history?

I was fighting the same problem as you and this is what I found:

PHP:

There is no such function in php, there is a way to replace a previous similar header in php though, but I don't think that this is what you are looking for! (php manual)

Javascript:

There are several functions and ways to directly or indirectly manipulate the browser history:

  • You can use window.location.replace("http://...") to redirect a user without saving the current page to the browser history
  • window.history.back() to redirect the user one page back in the browser history (acts exactly like the back button of the browser)
  • window.history.forward() same as window.history.back() but forward
  • window.history.go(index) loads a specific page from session history, using its relative position in session history as an index (the current page has the index 0)
  • for more information about manipulating the browser history with history.replaceState()and history.pushState() read this

To answer your question:

Depending on what you are doing you can use one of these js-methods. Unfortunately, as mentioned, there is no such thing in PHP if I'm not mistaken.