AngularJS SEO页面404标头状态代码 [英] AngularJS SEO Page 404 Header Status Code
问题描述
我们正在一个使用Symfony2 + AngularJS的项目中工作。
每个人都在不同的域中(Symfony2的api.domain和Angular项目的www.domain)。
现在,我们重点关注SEO部分。我们使用Prerender.io创建静态快照,以为爬网程序提供良好的HTML Raw页面。
但是问题在于在Angular上提供 404页面时:
$ urlRouterProvider
.otherwise('/ 404');
问题是,我们正在做的就是将不存在的页面重定向到我们的 404页面具有200的标题状态代码,这对于SEO而言非常糟糕...
由于AngularJS无法生成,我们已经尝试了两件事:
1。对htaccess / Apache使用重定向:
RedirectMatch 404 / 404
2。调用返回404错误的Web服务:
<!DOCTYPE HTML PUBLIC-// IETF // DTD HTML 2.0 // EN
< html>
< head>
< title> 404未找到< / title>
< / head>
< body>
< h1>未找到< / h1>
< p>在此服务器上找不到请求的URL / do-not-access。
< / body>
< / html>
对于AngularJS方面,我们试图抛出标头状态代码而没有成功:
返回$ http.get(ENV.apiEndpoint +'/ do-not-access');
这些都不适合我们...
我们也打算使用第二个 404页面。这个想法是通过带有404状态代码的htaccess将我们的第一个404页重定向到第二个404页,但是由于AngularJS内部重定向,我们认为这不起作用:
200-> 301-> 404
PS:我发现: AngularJS html5mode和hard 404 表示我们必须配置服务器以为您的自定义404页面设置路由例外,但是我们真的不知道如何会...
我们聚焦的方式不好吗?
还有其他选择吗?> p>
我们如何处理?
任何想法吗?
似乎 prerender.io 提供了一种处理 http标头状态的方法。
例如,对于 404页面,我们只需将此元标记添加到我们的head标签中:
<元名称= prerender状态代码 content = 404>
文档: https://prerender.io/documentation/best-practices
We are working in a project which uses Symfony2 + AngularJS. Each one in a different domain (api.domain for Symfony2 and www.domain for the Angular project).
Now we are focusing on the SEO part. We use Prerender.io to create static snapshots to serve a good HTML Raw page to crawlers.
But the problem is when serving the "404 Page" on Angular:
$urlRouterProvider
.otherwise('/404');
The thing is, what we do is redirecting a nonexistent page to our "404 Page" with a 200 Header Status Code, which is very bad for SEO purposes...
Since AngularJS is not capable of generating, we have already tried 2 things:
1. Use a redirection with htaccess / Apache:
RedirectMatch 404 "/404"
2. Call to a web service which return us a 404 error:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
<p>The requested URL /do-not-access was not found on this server.</p>
</body>
</html>
And for the AngularJS side we tried to throw the header status code without success:
return $http.get(ENV.apiEndpoint + '/do-not-access');
None of this worked for us...
We also though about using a second "404 Page". The idea was redirecting our first 404 page to this second 404 page via htaccess with a 404 status code, but we think that will not work due to AngularJS internal redirection:
200 -> 301 -> 404
PS: I found: AngularJS html5mode and hard 404 which says "we have to configure our server to make a routing exception for your custom 404 page" but we really have no clue how to do it...
Are we focusing in a bad way?
There is other option?
How we can handle it?
Any ideas?
It seems that prerender.io offers a way to handle http header status.
For example, for a 404 page we just need to add this meta tag into our head tag:
<meta name="prerender-status-code" content="404">
Docs: https://prerender.io/documentation/best-practices
这篇关于AngularJS SEO页面404标头状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!