How to retrieve the URL that was typed when a user lands on the 404 error page?

If you have a premium account, you can create a 404 page of your own,
and you can try adding some code to retrieve the page url (wixLocation) and save it to the database (I’ve never tried to do it, but I don’t see a reason why wouldn’t it work).