wbmnfktr Posted January 31, 2019 Share Posted January 31, 2019 Ok... I need your help and guidance with this. As the title says: How to get the Requested Page URL that ended in a 404? I'm looking for a ProcessWire-way of getting the originally requested URL that ended in a 404. Right now on a 404 page a $page->url will show /http404/ no matter what URL was requested. The parent is always id=1. There aren't any siblings or children. Technically that's totally fine and correct. But I'm kind of in need for something like $page->requestedUrl or $page->getForPage()->requestedUrl. Is there a hidden gem somewhere in the docs or a neat little trick for that? Why I'd like to have this? Because I'd like to check if there are any pages, in the same page tree or within the same topic or whatever similar to the requested one. Most 404 pages are kind of boring and in most cases there are no real benefits. I could just add some random blog posts if it's a blog or offer a search form but that's not the real deal. On a real estate site I'd like to show similar properties/houses/condos/whatever. On a recipe site similar recipes. And so on... Link to comment Share on other sites More sharing options...
adrian Posted January 31, 2019 Share Posted January 31, 2019 Not sure I really recommend it, but you could take a look at: http://modules.processwire.com/modules/process404-search/ It parses the URL from $_SERVER['REQUEST_URI'] and returns search results that match the url segment. Keep in mind that if anything, it is recommended to have a static 404 page, rather than one that does even more db queries: https://processwire.com/blog/posts/optimizing-404s-in-processwire/ 1 Link to comment Share on other sites More sharing options...
wbmnfktr Posted January 31, 2019 Author Share Posted January 31, 2019 Wow... thanks @adrian. This didn't show up on my radar but it's a big step forward and probably already the solution. I will definitely try this. The amount of 404 errors in this case is actually quite low (~100/month) and will not end in a performance issue. But you are correct. This could become an issue especially in the first time after moving a WP site over to ProcessWire. The optimization guide is great and I already had to dig into it once. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now