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
class BuildSitemap extends Controller
{
//
public function build(){
Sitemap::create()
->add($this->build_index(Blog::with('category')->get(), 'sitemap_blog.xml'))
->add($this->build_index(Report::with('category')->get(), 'sitemap_report.xml'))
->add($this->build_index(Event::all(), 'sitemap_event.xml'))
->add(Url::create(app()->getLocale() . '/')->setPriority(1)->setChangeFrequency(Url::CHANGE_FREQUENCY_ALWAYS))
->add(Url::create(app()->getLocale() . '/about/nav')->setPriority(1)->setChangeFrequency(Url::CHANGE_FREQUENCY_ALWAYS))
->add(Url::create(app()->getLocale() . '/contactus')->setPriority(1)->setChangeFrequency(Url::CHANGE_FREQUENCY_ALWAYS))
->add(Url::create(app()->getLocale() . '/blog ')->setPriority(0.5)->setChangeFrequency(Url::CHANGE_FREQUENCY_MONTHLY))
->add(Url::create(app()->getLocale() . '/event/all')->setPriority(0.5)->setChangeFrequency(Url::CHANGE_FREQUENCY_MONTHLY))
->add(Url::create(app()->getLocale() . '/report')->setPriority(0.5)->setChangeFrequency(Url::CHANGE_FREQUENCY_ALWAYS))
->add(Url::create(app()->getLocale() . '/team')->setPriority(0.5)->setChangeFrequency(Url::CHANGE_FREQUENCY_ALWAYS))
->writeToFile(public_path('sitemap.xml'));
}
protected function build_index($model, $path){
Sitemap::create()
->add($model)
->writeToFile(public_path($path));
return $path;
}
}
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/{"id":4,"user_id":1,"category_id":3,"title":{"en":"ewq","ar":"\u0627\u0644\u0642\u0628\u064a\u0644\u0647\u0627\u0644\u0642\u0628\u064a\u0644\u0647","fr":"rerss"},"description":{"en":"<p>ddd<\/p>","ar":"<p>sss<\/p>","fr":"<p>dd<\/p>"},"meta_description":{"en":"dd","ar":"dd","fr":"dd"},"photo":"","status":0,"views":0,"deleted_at":null,"created_at":"2024-09-22T20:36:10.000000Z","updated_at":"2024-09-22T20:36:10.000000Z","category":{"id":3,"title":{"en":"ss","ar":"ee","fr":"ddd"},"deleted_at":null,"created_at":"2024-09-22T20:35:36.000000Z","updated_at":"2024-09-22T20:35:36.000000Z"}}</loc>
</url>
</urlset>
In man sitemap.xml, we can see its only getting the /en/ language , other language not included
<?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.exmaple.com/sitemap_blog.xml</loc>
</url>
<url>
<loc>https://www.exmaple.com/sitemap_report.xml</loc>
</url>
<url>
<loc>https://www.exmaple.com/sitemap_event.xml</loc>
</url>
<url>
<loc>https://www.exmaple.com/en</loc>
</url>
<url>
<loc>https://www.exmaple.com/en/about/nav</loc>
</url>
<url>
<loc>https://www.exmaple.com/en/contactus</loc>
</url>
<url>
<loc>https://www.exmaple.com/en/blog </loc>
</url>
<url>
<loc>https://www.exmaple.com/en/event/all</loc>
</url>
<url>
<loc>https://www.exmaple.com/en/report</loc>
</url>
<url>
<loc>https://www.exmaple.com/en/team</loc>
</url>
</urlset>
Thank you so much for your help