Jump to content

What happens in an internal redirect? How to distinguish between 301 and 404


lpa
 Share

Recommended Posts

I am trying to implement server level analytics calling Matomo PHP tracking API from page footer.php that is included in every template. 

When I call for a renamed page URL handled by a 301 redirect, it seems to go first to '/http404/'. 

The $_SERVER['REQUEST_URI'] for the call is '/oldpath/pagename/'. It is handled by '/http404/' having URL '/http404/pagename/' in URL column when logging with `$log->message($page->url)`.  

I don't understand what is really happening here. How should I detect that the requested path was '/oldpath/pagename/' and that it caused a 301 redirect and it should not be tracked in Matomo as a page load?

Link to comment
Share on other sites

My straightforward question is: How can I determine on the '/http404/' page whether it's being accessed solely due to a redirect with a status code of 301 leading to the updated URL?

Link to comment
Share on other sites

What about the referrer? Would this help?

Haven't played around with error codes and 404 handling lately but I'd probably start with logging the referrer page in some way at least.

I guess $_SERVER['HTTP_REFERER'] might work here. Totally untested and just an idea for now.

Link to comment
Share on other sites

It seems to me, that the http404-page is rendered before the decission to redirect to the page in page path history is done. I would like to know when rendering http404, that there will be a redirect and the http404 page should not be tracked in Matomo as a page load. But I can't figure out how to detect this. 

HTTP_REFERER does not help, as I am interested to detect the forthcoming 301 before the 404 page is rendered.  

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...