SEO and Site Configuration – Sitemap & robots.txt

SEO is essential for discoverability. In this section, we configure our sitemap—which helps search engines index event registration URLs—and robots.txt—which directs crawlers to that sitemap and sets crawling rules.

Robots.txt Configuration

Defines crawler permissions and points to the production sitemap.

# public/robots.txt
User-agent: *
Allow: /
Disallow: /events/
Sitemap: https://events.prephoops.com/sitemap.xml
  • User-agent: * applies to all crawlers.
  • Allow: / lets bots access the root.
  • Disallow: /events/ prevents indexing of dynamic event pages.
  • Sitemap: URL of the sitemap on the production domain .
Directive Description
User-agent Target crawlers (* = all).
Allow Permitted path(s).
Disallow Path(s) to block from crawling.
Sitemap Location of sitemap for indexing.

Note: Always point to the live domain (events.prephoops.com) to guide bots correctly.

Sitemap Route

Maps /sitemap.xml to its controller.

// routes/sitemap.php
use App\Http\Controllers\SitemapController;
use Illuminate\Support\Facades\Route;

Route::get('sitemap.xml', [SitemapController::class, 'index']);

This route lives under the web middleware group .

Sitemap Controller

Gathers live events and renders an XML view.

// app/Http/Controllers/SitemapController.php
namespace App\Http\Controllers;

use App\Models\Event;
use Illuminate\Http\Response;

class SitemapController extends Controller
{
    /**
     * Render the events sitemap
     */
    public function index(): Response
    {
        $events = Event::latest()->get();
        return response()
            ->view('sitemap', compact('events'))
            ->header('Content-type', 'text/xml');
    }
}
  • Event::latest() fetches all live events sorted by creation date.
  • Response header text/xml signals an XML sitemap .

Sitemap Blade View 🗺️

Transforms event data into the sitemap XML format.

{{-- resources/views/sitemap.blade.php --}}
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    @foreach ($events as $event)
        <url>
            <loc>{{ $event->registrationLink() }}</loc>
            <lastmod>{{ $event->created_at->tz('UTC')->toAtomString() }}</lastmod>
            <changefreq>daily</changefreq>
            <priority>0.8</priority>
        </url>
    @endforeach
</urlset>
  • loc: Event registration URL.
  • lastmod: ISO-formatted last modification date.
  • changefreq & priority: SEO hints for search engines .

RouteServiceProvider Integration

Automatically includes the sitemap route.

// app/Providers/RouteServiceProvider.php
protected function mapSitemapRoutes(): void
{
    Route::middleware('web')
         ->group(base_path('routes/sitemap.php'));
}

Ensures the /sitemap.xml route is registered within the web middleware stack .

How It All Fits Together

  1. Crawlers request /robots.txt.
  2. robots.txt points to https://events.prephoops.com/sitemap.xml.
  3. Bots fetch /sitemap.xml.
  4. SitemapController compiles event URLs and serves an XML list.
  5. View (sitemap.blade.php) structures URLs in the proper schema.
flowchart TD
    A[Bot: GET /robots.txt] --> B{robots.txt}
    B -->|Sitemap: https://events.prephoops.com/sitemap.xml| C[Bot: GET /sitemap.xml]
    C --> D[SitemapController@index]
    D --> E[sitemap.blade.php view]
    E --> F[XML with event URLs]
    F --> G[Bot indexes URLs]

Best Practices Card

{
    "title": "SEO Best Practice",
    "content": "Keep robots.txt and sitemap URLs pointing to the live domain for accurate indexing."
}
  • Always verify robots.txt syntax (separate lines).
  • Update SitemapController logic when event URL patterns change.
  • Test XML validity after view modifications.