我的 angular 7 个应用程序 sitemap.xml 未被网站管理员工具选中

My angular 7 apps sitemap.xml is not being picked up by webmaster tools

我的 angular 7 个应用程序 sitemap.xml 没有被网站管理员工具选中

我有这个 sitemap.xml 文件(我隐藏了真实姓名):

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

  <url>
    <loc>https://mywebsite.co.uk/</loc>
    <lastmod>2018-11-28T13:11:30+00:00</lastmod>
  </url>

</urlset>

在网站管理员工具中,我不断收到此错误:

Your Sitemap appears to be an HTML page. Please use a supported sitemap format instead.

但我的文件是 .xml 文件。 所以我有点困惑。

这与 Angular 有什么关系? XML周围有没有HTML?

https://mywebsite.co.uk/sitemap.xml

上应该只有 XML

从我的网站复制的示例:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://mywebsite.co.uk/</loc>
    <changefreq>weekly</changefreq>
    <priority>1</priority>
  </url>
</urlset>

Below solution work for angular 2+ version:

Step 1: Create or add sitemap.xml under src/ or src/assets. Add url paths as shown in the example links.

Step 2: Add the following entry in your angular.json file

Step 3: Run your angular app and now you can access it via /Sitemap.xml

Step 4: Deploy your changes and access your sitemap.xml at yourdomain/assets/sitemap.xml

(注意:您也可以将 sitemap.xml 文件设置到 src 文件夹中)

  1. https://domain_name.com/assets/sitemap.xml
  2. http://localhost:4200/assets/sitemap.xml