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

TarikAli's avatar

laravel site map multi language

i have a site example.com with multi language so it redirect to example.com/ar , example.com/en and so on. the problem is i want to put site map file for every language like that example.com/ar/sitemap.xml ,

example.com/en/sitemap.xml but i havent folder named ar and en when i creat folder ar and put site map file in it

google approved but my site gives me 403 error forbidden and cant redirect to example.com/ar because the folder

has only site map file. now do i have to put a copy of public folder into every language folder beside site map file

tahnks.

0 likes
6 replies
Snapey's avatar
Snapey
Best Answer
Level 122

You could look at generating the site map on the fly in response to a request?

So have a route for {language}/sitemap.xml that streams the map as a view.

TarikAli's avatar

do you mean make route {language}/sitemap.xml and make function generates site map at run time

Zoul's avatar

Hi @tarikali , could you please share your code ? I've been stuck for this a long, trying to find a solution for mulit sitemap lang, thanks

TarikAli's avatar

@zoul

		  $name = 'sitemap_'.$lang->alies.'_.xml';

          $post_sitemap = '<?xml version="1.0" encoding="UTF-8"?>';
          $post_sitemap .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

		//	loop throw your posts to get $link
                $post_sitemap .= '<url>';
                $post_sitemap .= '<loc>'.$link.'</loc>';
                $post_sitemap .= '<lastmod>2021-06-21</lastmod>';
                $post_sitemap .= '<changefreq>monthly</changefreq>';
                $post_sitemap .= '<priority>1.0</priority>';
				$post_sitemap .= '</url>';

$post_sitemap .= '</urlset>';


File::put('sitemap/'.$lang->alies.'/'.$name, $post_sitemap);


Please or to participate in this conversation.