Using Algolia for a better 404 experience #6651
Unanswered
mmorris8
asked this question in
Show and tell
Replies: 1 comment
-
This is very interesting! I remember a project we made internally once that adds algolia in the DNS layer to automatically redirect to existing typo matching pages. This is of course a more realistic way to search for the pages that are similar to the current one. Thanks for sharing 🦋 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Most 404 errors are off by one letter typos. So I wanted to have Algolia do a search on just the link facet to get matches, and do this while PHP renders the 404 page. This wasn't as straight forward as I thought, so I figured I'd shared.
I resorted to using a replica index of my main wordpress search index that is configured to search only on the link facet. If there's a better way to accomplish this I'm all ears - not too happy about needing to use up an index to do this.
After that the build was pretty close to the PHP examples given in the docs
Note, I maintain different indexes for different environments. This allows me to try out different configurations without disturbing prod.
And in the Twig template we print this out. (I use Timber / Twig to render pages as using PHP directly is horrible).
Hope someone finds this useful.
Beta Was this translation helpful? Give feedback.
All reactions