Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

create Canonical URL in Laravel

How to add the canonical tag in Laravel?

In this tutorial, I will give you an example of “How to add the canonical tag in Laravel”, So you can easily apply it with your laravel 5, laravel 6, laravel 7, laravel 8, and laravel 9 application.

First, what we’re doing here, This is the example :

canonical tag in Laravel

What is a canonical tag in Laravel

A canonical tag (or “rel canonical”) is a way of telling search engines that a specific URL represents the master copy of a page. Using the canonical tag prevents problems caused by identical or “duplicate” content appearing on multiple URLs.

Practically speaking, the canonical tag tells search engines which version of a URL you want to appear in search results.

Canonicalization matter in Laravel

Duplicate content is a complicated subject, but when search engines crawl many URLs with identical (or very similar)
content, it can cause a number of SEO problems. First, if search crawlers have to wade through too much duplicate
content, they may miss some of your unique content. Second, large-scale duplication may dilute your ranking ability.

Related article: How to add dynamic meta tags in Laravel.

Finally, even if your content does rank, search engines may pick the wrong URL as the “original.” Using canonicalization helps you control your duplicate content.

Let’s create a canonical tag in the header file in Laravel :-

resources\views\layouts\header.blade.php

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>@yield('title')</title>
  <meta name="description" content="@yield('description')">
  <meta name="keywords" content="@yield('keywords')">
  <meta name="robots" content="index, follow" />
  <meta name="author" content="" />
  <meta name="copyright" content="" />
  <link rel="canonical" href="{{ url()->current() }}">
</head>

Read also:- Call the helper function in the blade file in Laravel 8.