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.

To confirm the bug, 

* cd test
* rackup
* visit racked up page with webkit browser
* click 'A page that errors should error out' link
* click browser back button


Webkit bug report
https://bugs.webkit.org/show_bug.cgi?id=93506

jquery.pjax code
https://github.com/defunkt/jquery-pjax/blob/master/jquery.pjax.js#L351-L360