Level 58
To create a sitemap.xml file for your website, you can use a package like Laravel Sitemap. Here are the steps to install and use it:
- Install the package using Composer:
composer require spatie/laravel-sitemap
- Publish the configuration file:
php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=config
- Open the
config/sitemap.phpfile and configure the URLs you want to include in the sitemap:
return [
'default' => [
'url' => [
'https://example.com',
'https://example.com/about',
'https://example.com/contact',
],
],
];
- Generate the sitemap.xml file:
php artisan sitemap:generate
- The sitemap.xml file will be generated in the
publicdirectory of your Laravel project. You can submit it to Google Search Console by adding it to your website's robots.txt file:
Sitemap: https://example.com/sitemap.xml
That's it! Your website now has a professional sitemap.xml file that you can submit to Google Search Console.