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

2

2

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

I have this sitemap.xml file (I've hidden real names):

<?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>

In webmaster tools I keep getting this error:

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

But my file is a .xml file. So I'm a bit confused.

Obreption answered 19/12, 2018 at 12:16 Comment(0)
R
2

How is this related to Angular? Is there HTML around the XML?

There should be XML only on https://mywebsite.co.uk/sitemap.xml

Copied Example from one of my sites:

<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>
Recusant answered 19/12, 2018 at 12:50 Comment(6)
Looks like google cant find my sitemap.xml for my angular 7 appObreption
do you need to create a sitemap.xml route in the angular routing?Obreption
No, you just put a static xml file there. You have to make sure to have it available at example.com/sitemap.xml If you are using the Angular CLI, look at this tutorial: thecodecampus.de/blog/angular-cli-sitemap-robots-txtRecusant
thanks for that link - really good - looks like i needed to update my angular json assets array - I will test nowObreption
@Obreption did you manage to sort this issue? I can see my sitemap.xml when typing it into the URL, but Google still gives me a couldn't fetch error.Derr
@Can Can you please let me know how can I update sitemap.xml at runtime using angular 9?Leija
M
0

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.

enter image description here

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

enter image description here

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

(Note: You can also set your sitemap.xml file into src folder as well)

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

enter image description here

Meat answered 27/7, 2020 at 8:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.