Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Zoul's avatar
Level 5

Sitemap is not working on multi language website

Hi all,

I have a multilanguage webiste, when i generate the sitemap.xml, it only getting the english urls. also the main sitemap.xml show the urls for 5 seconds and then all disappear again, don't know why.

the sitemap.xml is also accessible via www.example.com/sitemap.xml so it should also get the local language such as www.example.com/en/sitemap.xml

In BuildSitemap class

In Blog Model


    public function toSitemapTag(): Url | string | array
    {
        return Url::create(route('blog.details', $this))
            ->setLastModificationDate(Carbon::create($this->updated_at))
            ->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
            ->setPriority(0.1);
    }

In sitemap_blog.xml

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
    <url>
        <loc>https://www.example.com/{&quot;id&quot;:4,&quot;user_id&quot;:1,&quot;category_id&quot;:3,&quot;title&quot;:{&quot;en&quot;:&quot;ewq&quot;,&quot;ar&quot;:&quot;\u0627\u0644\u0642\u0628\u064a\u0644\u0647\u0627\u0644\u0642\u0628\u064a\u0644\u0647&quot;,&quot;fr&quot;:&quot;rerss&quot;},&quot;description&quot;:{&quot;en&quot;:&quot;&lt;p&gt;ddd&lt;\/p&gt;&quot;,&quot;ar&quot;:&quot;&lt;p&gt;sss&lt;\/p&gt;&quot;,&quot;fr&quot;:&quot;&lt;p&gt;dd&lt;\/p&gt;&quot;},&quot;meta_description&quot;:{&quot;en&quot;:&quot;dd&quot;,&quot;ar&quot;:&quot;dd&quot;,&quot;fr&quot;:&quot;dd&quot;},&quot;photo&quot;:&quot;&quot;,&quot;status&quot;:0,&quot;views&quot;:0,&quot;deleted_at&quot;:null,&quot;created_at&quot;:&quot;2024-09-22T20:36:10.000000Z&quot;,&quot;updated_at&quot;:&quot;2024-09-22T20:36:10.000000Z&quot;,&quot;category&quot;:{&quot;id&quot;:3,&quot;title&quot;:{&quot;en&quot;:&quot;ss&quot;,&quot;ar&quot;:&quot;ee&quot;,&quot;fr&quot;:&quot;ddd&quot;},&quot;deleted_at&quot;:null,&quot;created_at&quot;:&quot;2024-09-22T20:35:36.000000Z&quot;,&quot;updated_at&quot;:&quot;2024-09-22T20:35:36.000000Z&quot;}}</loc>
    
            </url>
</urlset>

In man sitemap.xml, we can see its only getting the /en/ language , other language not included

Thank you so much for your help

0 likes
2 replies
tisuchi's avatar

@zoul So, do I understand you correctly?

You want to include a sitemap for all available languages.

However, it looks like your current sitemap generation is only considering the URLs in one language (English in this case) instead of including all the available languages.

To fix this you should include URLs for multiple languages. Here is my thought:

  • Loop through all available locales (languages) to generate a sitemap for each language version of the URLs.
  • Add the alternative language links (xhtml:link) for each URL to indicate the other language versions.
Zoul's avatar
Level 5

Thanks @tisuchi will make a loop and see. Any idea why the main sitemap.xml does not hold the generated URLs, they just appear for 5 second then disappear again ?

Please or to participate in this conversation.