Thanks, I'll try that!
EDIT: Not working yet.
I added the global.asax, added your code to the Application_Error handler, and rebuilt. I made one change, because I think a true 404 would otherwise cause an infinite loop:
(httpCode == 404)
.Context.Request.Url.Segments.Length - 1];
But this hasn't made a difference, I still see the 404 page with the same missing URL. (I also restarted IIS, just to be sure.)