AngularJS html5mode and hard 404

I have an AngularJS application working with html5mode set to true .

Currently, the application shows a soft 404 page with the .otherwise in the router.

Is there a way that I could serve the actual 404 HTTP response, for the sake of SEO, using html5mode?

+3
javascript angularjs seo
source share
3 answers

If I understand correctly what you want, you should do the following:

  • hard redirect the browser (bypassing angular routing) otherwise, with something like this:

     $routeProvider .otherwise({ controller: function () { window.location.replace('/404'); // your custom 404 page // or a non existing page } }); 
  • if you have a regular one-page application in which all server requests are redirected to the same SPA entry point, you need to configure it on your server to make a routing exception for your 404 user page, which should also be served with 404 status.

Otherwise, I can’t understand how you will do this using only the history API, without an external request, because all this in angular routing is to bypass external requests.

If you want non-existent routes to return 404, you must configure your server to match all your angular routes and otherwise return 404.

+2
source share

Seach engines work with SPA applications through preloaded pages using _escaped_fragment_. And you can use Prerender.io (or just PhantomJS) to generate any status codes for search engines like https://prerender.io/documentation/best-practices

But this scheme is deprecated by Google: http://googlewebmastercentral.blogspot.ru/2015/10/deprecating-our-ajax-crawling-scheme.html At this point, Google is trying to understand your JS with a regular workaround.

Hard redirecting to a 404.html page is not good practice: the url should remain unchanged, for example https://stackoverflow.com/somepage

You can try Angular2 with the server rendering function: https://docs.google.com/document/d/1q6g9UlmEZDXgrkY88AJZ6MUrUxcnwhBGS0EXbVlYicY/edit

0
source share

You have to make your server 404 problem. Angular cannot help in any way.

0
source share

All Articles