Search code examples
phpxmllaravelroutessitemap

Adding Sitemap file and route in laravel


I have a sitemap.xml file in my view folder and this is the route:

Route::get('sitemap.xml',function() {
return response()->view('sitemap')
->header('Content-Type', 'xml');
});

But when i search mydomainname.com/sitemap.xml. It returns InvalidArgumentException View [sitemap] not found.

I tried to search on google and youtube but not able to find any solution.


Solution

  • I moved sitemap.xml file to the public directory and the route would be:

    Route::get("sitemap.xml" , function () {
    return \Illuminate\Support\Facades\Redirect::to('sitemap.xml');
     });
    

    Now open the xml file through url: www.domain.com/sitemap.xml