Taking the 404 further
Update: I have now written a WordPress plugin that does all of this for you. Please use this plugin instead.
I’ve just changed my permalink structure for my blog to something a bit prettier. In the process, I realised that some previously-working permalinks weren’t operating any more, despite having a plugin set up to maintain old permalinks.
WordPress is fairly good at figuring out what viewers are requesting when a post can’t be found immediately – for example, if you’re using a permalink structure with an ID number in it, and the requested ID is incorrect, WordPress seems to be able to redirect to the correct address.
However, it’s not 100%, as I recently realised.
Consequently, a few pages were heading to the 404 page, which isn’t ideal. I changed my template’s 404 page to do a search for what the viewer was really after, and redirect them there. If it can’t find an exact match, it’ll perform a search with keywords extracted from the URL. If it finds a single result, it’ll redirect, otherwise it’ll put up a few results as suggestions on the 404 page.
It also works as a nice search shortcut. Try it: http://atastypixel.com/wordpress 404 redirect
Read More