Hello, I'm having trouble to upload sitemap and getting it to work. I have a controller where I'm trying to return a view to the public folder where I'm storing my sitemap.xml file. I'm trying to use Google Search Console and read mydomain.is/sitemap but I can't figure out how to load the file from Laravel.
My Controller is like this:
class SitemapController extends Controller
{
public function index()
{
return view(asset('sitemap.xml');
}
}
It would be far more efficient to actually create a sitemap.xml file and put it in the root of your site. That could be created manually, or you could code it to automatically generate the xml file and use it in a scheduled task to keep it updated.
Also, your route is only responding to 'sitemap', not 'sitemap.xml', which is what the search engines will try to load.
If you want to return a sitemap.xml in an view you must create a blade file for it in the resources/views folder and name it like sitemap.blade.php. This way you can use the blade system to dynamicly create the file.
If your sitemap is static, I suggest putting it in the public folder so that the file will be handled as an normal file by the webserver so it will skip the framework at all.
@SNAPEY - Im jusing this package, but im not sure if I need to make Route for it or anything like that. I have this file in the public folder and I connected Google Search Engine to /sitemap