Replace history and location when xhr response status is 40x.

webkit has a bug in history state api. It occurs when 404 page is pushed to
history state and then reload the page.
This commit escape the bug with code retrieved from jquery.pjax.