Sitemap Generation

Laratic includes a powerful sitemap generation system that automatically discovers all public routes and creates an optimized XML sitemap for search engines using the Spatie Sitemap package. The sitemap is intelligently filtered to exclude authentication routes, admin areas, and other private pages while including all public content, documentation, and blog posts.

Generating the Sitemap

The sitemap is generated using a simple Artisan command. This command can be run manually or scheduled to run automatically to keep your sitemap up to date with the latest content:

php artisan sitemap:generate

After running this command, your sitemap will be saved to public/sitemap.xml and will be accessible at yoursite.com/sitemap.xml.

What's Included

The sitemap automatically includes:

  • Public Static Routes - All publicly accessible pages like home, features, pricing, contact, etc.
  • Documentation Pages - All documentation files are automatically discovered and included
  • Blog Posts - Active blog posts with their last modification dates
  • Priority Optimization - Each URL is assigned an appropriate priority value based on its importance

What's Excluded

The sitemap intelligently excludes routes that should not be indexed by search engines:

  • Authentication routes (login, register, password reset)
  • Admin routes and authenticated-only areas
  • API endpoints
  • Internal routes (debugbar, webhooks, etc.)
  • Livewire component routes
  • Routes requiring authentication middleware

Customizing Priority Values

Each URL in the sitemap is assigned a priority value between 0.0 and 1.0. You can customize these values by editing the priority map in app/Console/Commands/GenerateSitemap.php:

// Define priority mapping for specific routes
$priorityMap = [
    'home' => 1.0,        // Highest priority
    'pricing' => 0.9,     // Very high priority
    'features' => 0.8,    // High priority
    'blog' => 0.8,        // High priority
    'careers' => 0.7,     // Medium-high priority
    'about-us' => 0.7,    // Medium-high priority
    'contact' => 0.7,     // Medium-high priority
    'waitlist' => 0.6,    // Medium priority
    'terms' => 0.5,       // Lower priority
    'privacy' => 0.5,     // Lower priority
];

Adding Custom Routes

If you need to manually add specific routes to your sitemap, you can modify the addPublicRoutes() method in the GenerateSitemap command:

// Add a custom route
$sitemap->add(
    Url::create(route('your.custom.route'))
        ->setPriority(0.8)
        ->setChangeFrequency(Url::CHANGE_FREQUENCY_WEEKLY)
);

Excluding Specific Routes

To exclude additional routes from the sitemap, add them to the shouldSkipRoute() method in app/Console/Commands/GenerateSitemap.php:

// Skip your custom routes
if ($name === 'your.route.name') {
    return true;
}

// Or skip by URI pattern
if (str_starts_with($uri, 'internal/')) {
    return true;
}

Troubleshooting

If you encounter issues with sitemap generation:

  • Ensure the public directory is writable
  • Check that all routes are properly named in your route files
  • Verify that the Spatie Sitemap package is installed (composer require spatie/laravel-sitemap)
  • Clear your route cache with php artisan route:clear