The site has a bunch of redirects that are spread over php routing. And there are situations like

/ site / loop1> / site / loop2

/ site / loop2> / site / loop3

/ site / loop3> / site / loop4

/ site / loop4> / site / loop5

/ site / loop5> / site / loop6

I give myself the accountability that before a redirect it is possible that “something” is happening (it is written during the session or something else). But obviously it is necessary to get rid of this, so that in the end a direct redirect will turn out

/ site / loop1> / site / loop6

The blessing though all redirects are made through a wrapper, a certain function redirect in which I would like to put redirects in a stack and if the chain was formed. At the end point of the exit, it was written to me somewhere (for example, to a database). For further disentanglement of this ball.

So far it only comes to mind that $_SERVER['HTTP_REFERER'] added to the session with each redirect and analyzed after leaving the chain.

How is it properly organized, so I did not do a bicycle?

  • Where do they come from, these redirects? The reason for their creation? - Visman
  • And what, you do not know how to use debag? - Alexey Shimansky
  • one
    @Visman, Good people have put it. Mostly SEOs are "optimized." And then they are surprised that the pages open for a long time. - Ninazu
  • @ Alexey Shimansky. Apparently not. In more detail. Got automated turnkey solutions? - Ninazu
  • one
    @Ninazu rewrite from scratch ¯ \ _ (ツ) _ / ¯ - Alexey Shimansky

2 answers 2

I would try the following method, maybe it will be working:

  1. Inside the redirect function, create or add to the end of a separate cookie redirect URL. For example, the third redirect will have the same value in the cookie: "/ site / loop1; / site / loop2; / site / loop3"

  2. In the final application script (before responding to the client), check the presence of the "Location" header in the response. If not, then write this cookie value to the database in any convenient way and reset this cookie.

  3. ...

  4. Profit!

  • I also thought about the cookies at the beginning. Otherwise, how else to make the client give what we send him. But I think that the session will be correct. It is possible that a redirect goes to a subdomain or alias for example and then back. Well, cookies can be disabled) - Ninazu

Write a plugin, for example, for Chrome, it’s quite simple to do this, and when opening the desired site on one of the tabs, follow the page evolution.
This is if the redirect is sent to the client, and does not fully work out inside the "back end" (backend) of the site.