We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1511
    • 144 Posts
    Is there a way (other than checking the web server logs) to get the URLs of requests creating a "404 error"?

    I have redesigned a web site but I have some "404 error" responses, since some folks have bookmarks set to old pages and I do not cover them all.
    I’d like to see which URLs are they requesting.


      • 25663 MODX Staff
      • 12,272 Posts
      Theoretically you could create a plugin that watches for requests to the page that sends the 404 ... interesting idea.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 1511
        • 144 Posts
        Is there anything done already?

        If not, I can dig into it, since I’m interested in MODx core functions and the whole lot that comes around it. smiley

        Otherwise you could just add it in a log... but system events is for other purposes.
          • 25663 MODX Staff
          • 12,272 Posts
          Nothing has been done to date. Thanks for digging in!
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 1511
            • 144 Posts
            Ok, got the plugin already working.

            Now I’m into a module that will browse the results. This will take a bit more of my time, since I’m coding during my breaks. smiley
              • 18397
              • 3,250 Posts
              $modx->logEvent might be of use to store a message in the event log
                • 1511
                • 144 Posts
                Yes, I’ve seen it. But have a different idea about it.

                There can be many entries and they are not as such (at least in my opinion) system events + in a module of its own I can add other functionality. Give me a day or two and something will come out.
                  • 27376
                  • 576 Posts
                  I created a simple plugin that uses the MODx message system to notify me of 404s, but the system alert sounds like a better idea!

                  Here’s what I’ve got:
                  <?php
                  /**
                   * Page Not Found Notifier
                   *
                   * Events Checked: OnPageNotFound
                   */
                  $evt =& $modx->event;
                  
                  $server_info = '';
                  foreach ($_SERVER as $k => $v) $server_info .= sprintf("\n<b>%s:</b> %s", $k, $v); // Format all the server vars...
                  
                  $msg = sprintf(
                  "A 404 message was received from the website<br/>
                  <br/>
                  <b>Server Infos:</b> %s",
                  $server_info
                  );
                  
                  // This line could easily be changed to logEvent after moving some params around...
                  $modx->sendAlert('Error', 1, 0, 'Page Not Found!', $msg, 0);
                  ?>

                  The plugin includes all the server vars with the log, including the HTTP_REFERER. Have fun!
                    • 1511
                    • 144 Posts
                    Well, here it goes. It’s my first plugin and my first module written for MODx. First version. smiley

                    I hope it works. Open to suggestions.

                    Documentation is only temporary. Actually, there is almost none. I’ll write some tomorrow.


                    edit: new version below
                      • 27376
                      • 576 Posts
                      andrazk, it may be useful to also save the HTTP_REFERER variable so that you have an idea of where they are coming from. Sometimes the variable isn’t populated but most of the time if a human is browsing and hits of 404 page, the HTTP_REFERER variable is populated.

                      Great plugin/module though! I’ll start using it if the HTTP_REFERER is added smiley