How can I detect if page was requested via a redirect?

后端 未结 6 747
北海茫月
北海茫月 2021-01-06 05:00

On a client\'s website there are loads of redirects going to a particular page. This page somehow needs to have a way detecting whether the request was direct (URI typed in

6条回答
  •  自闭症患者
    2021-01-06 05:26

    Depending on the browser and intermediate proxies, several things can happen. However, in most cases you can't depend on any one thing. The status codes are something the server sends back to the browser, so you won't get those in a request.

    You don't say what problem you are trying to solve or why this bit is important. What problem are you trying to solve?

    Instead of relying on something you don't control, turn it into something you can control.

    1. Ensure that you're doing the right sort of redirect. There are redirections for permanent and temporary moves as well as other situation.

    2. If you don't need the data in real time, you can figure out from log files. This is handy if you're trying to figure out traffic patterns, but not so useful in real time.

    3. Instead of an external redirection, make it an internal redirection. You can track it through your web server's request cycle.

    4. Set a cookie on the external redirection then look for it in the next request. This won't catch the people who don't set cookies though.

    5. Add path info to the redirection, or maybe query parameters as Sinan suggested.

提交回复
热议问题