shahr's avatar
Level 10

How to create a sitemap.xml

I'm a newbie. I have been coding my website for 2 weeks, and now the job is going to be finished, But I don't know how to make a professional sitemap.xml for google console. Please help me to make a professional sitemap.xml for google console.

0 likes
1 reply
LaryAI's avatar
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:

  1. Install the package using Composer:
composer require spatie/laravel-sitemap
  1. Publish the configuration file:
php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=config
  1. Open the config/sitemap.php file 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',
        ],
    ],
];
  1. Generate the sitemap.xml file:
php artisan sitemap:generate
  1. The sitemap.xml file will be generated in the public directory 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.

Please or to participate in this conversation.