Put this to your layout blade file.
<link rel="canonical" href="{{ url()->current() }}">
Docs: https://laravel.com/docs/8.x/urls#accessing-the-current-url
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
How do I generate a canonical URL for every page on my Laravel app? Basically, I am building a content management system that will have thousands of pages each requiring a canonical link pointing to www.sitename.com/path-to-page
@cocotmu In that case you can use something like this:
@if ($articles->currentPage() === 1)
<link rel="canonical" href="{{ url()->current() }}" />
@else
<link rel="canonical" href="{{ url()->current() }}?page={{ $articles->currentPage() }}" />
@endif
Please or to participate in this conversation.