More work on the 404s

I think this now works pretty much as expected. This adds in our 404 pages where appropriate. 
This is a combined pull request from @ascott1 and me. 

@cmc333333 I would appreciate a careful code review, as bits of this were written late last night.