AngularJS SEO for 404 Status for Document与本网站类似

Hol*_*lly 7 seo angularjs

我正在试图找出如何在我的AngularJS应用程序上找到页面未找到404文档状态错误以保持良好的SEO.我想做一些类似于Red Bull Sound Select网站的做法,但我不确定他们是怎么做到的?

示例404 URL

https://www.redbullsoundselect.com/no-page-here 在此输入图像描述

正如您在上面的示例中所看到的,URL更改为/ 404,并且您在URL中的原始路径中获得404文档状态错误,即无页面 - 此处



在我的AngularJS应用程序上,我只有:

.otherwise({
    class: 'page-not-found',
    title: '404 Page Not Found',
    description: '404 Page Not Found',
    templateUrl: '/app/static/404.html',
    controller: 'mainController as mainCtrl'
});
Run Code Online (Sandbox Code Playgroud)

我可以使用类似的东西:

otherwise({
    redirectTo: '/404'
});
Run Code Online (Sandbox Code Playgroud)

这类似于redbull站点的内容,但它仍然没有给出404文档状态错误.(也将URL更改为404而不是维护原始URL,这对SEO来说也不是很好,但至少谷歌不会将错误的URL编入索引.)

我想我可以尝试在Angular中创建一个不存在的http请求以获得404 xhr状态,但我不认为这就足够了.

我已经阅读了一些建议使用prerender.io的答案,但这是你必须付出的代价,这似乎只是让404页面正常工作.

也许,我们可以在.htaccess中做一些事情,以便不同地处理404页面?目前我们已经重写规则,以便任何不存在的请求资源都使用/index.html.也许我们可以对Apache中如何处理404页面做出例外.

UPDATE

我在redbullsoundselect.com上发现他们在app.js中使用了以下内容

$stateProvider.state("404", {
  url: "/404",
  templateUrl: "/views/site/404.html",
  controller: "NotFoundController"
});
Run Code Online (Sandbox Code Playgroud)

虽然,我仍然不明白这个逻辑是如何工作的.我查看了他们的NotFoundController,但似乎没有发生太多.

它可以与他们使用ui.router而不是ngRoute像我一样吗?

第二次更新

这是我的.htaccess设置:

RewriteEngine On
  # If an existing asset or directory is requested go to it as it is
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
  RewriteRule ^ - [L]
Run Code Online (Sandbox Code Playgroud)

#如果请求的资源不存在,请使用index.html RewriteRule ^ /index.html

San*_*rsh 5

RedBull Sound Select正在做什么

有效网址:https://www.redbullsoundselect.com/artists/gherbo

网址无效:https://www.redbullsoundselect.com/artists/gherbo2

打开DevTools,在"网络"选项卡中选择"保留日志",打开无效的URL.

  1. Angular app加载了200或304(如果在缓存中)
  2. 进行API调用 /api/v1/groups/gherbo2?type=artist
  3. API以404响应
  4. Angular代码执行window.location.assign("/404"); artists-profile.js:577

他们为Angular文件提供服务的Express应用程序知道有效的URL模式,如果URL与定义的模式不匹配,则发送404.但是,如果URL匹配上述无效UR​​L之类的模式,则Angular将window.location.assign用于导航到新页面.

crawler(GoogleBot)将如何表现

  1. 我们假设Google访问了无效的网址
  2. 它获得的第一个响应代码是200
  3. 现在Google可能会也可能不会执行JS.资源
  4. 如果它执行JS,Angular会尝试将其导航到新页面.(这里不确定爬虫会如何反应)

总的来说,在我看来,这不是一个很好的SEO设置(对于用户来说,这是好的).我们正在将自托管的Prerender集成到我们的Angular部署中.

Prerender是MIT许可下的开源软件.

我们在prerender.io上托管这个服务,但我们也开源,因为我们相信基本的SEO是一种权利,而不是特权!