How to display the current page's canonical URL in the template to optimize SEO?

Calendar 👁️ 101

In website operation, Search Engine Optimization (SEO) is one of the core tasks to enhance website visibility.The setting and correct display of the canonical URL (Canonical URL) is crucial for avoiding content duplication, optimizing crawling efficiency, and concentrating page weight.AnQiCMS (AnQiCMS) is a highly SEO-focused enterprise-level content management system that provides users with convenient tools for managing and deploying standard links.

What is a canonical URL (Canonical URL)?

The norm link, as the name implies, is to inform the search engine of the 'normative' or 'preferred' version of a web page.In the operation of a website, for various reasons, the same content may be accessed through different URL addresses.

  • http://www.yourdomain.com/pageandhttps://www.yourdomain.com/page
  • yourdomain.com/pageandwww.yourdomain.com/page
  • yourdomain.com/page?id=1andyourdomain.com/page?source=ad

These URLs may be different, but they point to content that is completely the same or highly similar.If not handled, search engines will treat it as duplicate content, which may lead to reduced crawling efficiency, affected page rankings, and even diluted link weight obtained from different URL versions.The purpose of the specification link is to clearly inform search engines which URL is the main content or the 'official' version, thereby concentrating all signals to the preferred URL.

The importance of canonical URL for SEO

Using canonical URL correctly can bring multiple SEO benefits to a website:

  1. Avoid duplicate content issues:This is the most important function.Standard links can effectively resolve the problem of duplicate content caused by URL parameters, session ID, HTTP/HTTPS version, and WWW/non-WWW version.
  2. Concentrate link weight:When multiple URLs point to the same content, the weight of all external links (external links) pointing to these URLs will be dispersed.By linking to the standard, these scattered weights can be unified and concentrated to the preferred standard URL, thereby enhancing the overall weight of the page.
  3. Improve crawling efficiency:The crawl budget of search engines is limited.By specifying clear guidelines, search engines can avoid repeated crawling and indexing of the same content under different URLs, using valuable crawling resources to discover new content or more important content on websites, and improving the overall crawling efficiency of the website.
  4. Improve search results display:Search engines tend to display standard URLs in search results, which helps improve user experience and avoids users clicking on non-preferred duplicate pages.

Set the specification link in the AnQiCMS background

The AnQiCMS backend design fully considers SEO requirements, you can directly set standard links for each page when publishing or editing documents.This feature is usually used when you want to direct the weight or traffic of the current document to another specific page, for example, when you have the same content but published on different platforms, or when you need to direct to a specific page in a particular marketing campaign.

The specific operation path is: go to the background“Content Management”, select“Document Management”or“Page Management”, click the document or page you want to edit. In the editing interface,“Other Parameters”section, you will find a name called“Standard Link”Input box.

Here, you need to fill in acomplete URL addressi.e., withhttporhttpsa full path link starting with, for examplehttps://www.yourdomain.com/article/your-preferred-page.Make sure the link is correct, an incorrect standard link may cause unexpected SEO problems.If your page does not have a specific specification link to point to, it is usually okay to keep it empty, AnQiCMS will automatically handle self-referencing specification links.

Display the specification link in the AnQiCMS template

After setting the specification link in the background, the next most critical step is to output this correctly on the front-end page of the website<link rel="canonical">Tags. AnQiCMS provides powerful template tags that can easily achieve this.

To display the specification link of the current page, you can use the built-in AnQiCMStdk(Title, Description, Keywords) tag, it also supports obtaining the standard link information of the page. Usually, this tag is placed in the website template file (such asbase.htmlOr detail page template) of<head>Within the area.

The following is the recommended code snippet for displaying specification links in the AnQiCMS template:

{%- tdk canonical with name="CanonicalUrl" %}
{%- if canonical %}
<link rel="canonical" href="{{canonical}}" />
{%- endif %}

Let's parse this code step by step:

  1. {%- tdk canonical with name="CanonicalUrl" %}:

    • tdkIt is a tag used by AnQiCMS to obtain page TDK information.
    • canonicalIt is a variable name you custom for the standard link data you obtain, you can name it according to your habits.
    • with name="CanonicalUrl"We specified thattdkThe data type obtained from the tag is “CanonicalUrl”.
    • Before the tag{%-And after the tag%}of-The symbol is used to remove the extra whitespace generated by the tag line, making the output HTML code cleaner.
  2. {%- if canonical %}:

    • This is a conditional statement. It checks the custom-definedcanonicalThe variable exists and has a value.
    • This judgment is very important because not all pages need to manually set the specification link in the background. IfcanonicalThe variable is empty, then nothing will be output.<link rel="canonical">The tag avoids outputting empty links or unnecessary code. Similarly,{%-Used to remove whitespace.
  3. <link rel="canonical" href="{{canonical}}" />:

    • IfcanonicalIf the variable has a value, this line of HTML code will be output to the page's<head>area.
    • rel="canonical"It is a standard HTML attribute, telling the search engine that this is a valid link.
    • href="{{canonical}}"Insert the valid link value we obtained from the backend intohrefthe attribute.

Add the above code to your website template's<head>part (usuallybase.htmlFile, so that all pages can inherit), it can ensure that each page can output the standard link according to the background settings.

**Practical Tips and Warnings

  • Unified across the entire site:Ensure that your standard link always uses the preferred domain of the website (for example, withwwwor withoutwww) and a unified protocol (HTTPorHTTPS). For example, if you decide to usehttps://www.yourdomain.comAs a preference, all specification links should appear in this format.
  • Self-referential specification links:Even if the page does not have duplicate content, it is strongly recommended to set a link pointing to itself.AnQiCMS will usually intelligently use the URL of the current page as the self-reference specification link when you do not manually fill in the specification link.
  • Use with caution:The specification link is not万能, should not be滥用.For pages that have been paginated, sorted, or filtered, it should be judged according to the actual situation whether it is necessary to set a standard link.Sometimes, these pages themselves are of unique value and should not be standardized to the main page.
  • Avoid chained and incorrect links:Avoid linking the specification link to a page that has already set a specification link (i.e., do not have A specification to B, B specification to C), or to a 404 error page.This will confuse the search engine.
  • Dynamic page handling:For dynamic list pages with filtering and sorting parameters, the usual practice is to make them point to themselves (self-referencing) or to a 'clean' version of the URL without any parameters, depending on whether these parameters will significantly change the content of the page.

Through AnQiCMS's convenient settings and powerful template features, you can easily implement standardized link deployment, effectively manage the SEO of your website, and make your website content perform better in search engines.


Frequently Asked Questions (FAQ)

Q1: I have set up the specification link in the background, why doesn't it show up on the website front end?A1: First, please confirm whether you have added the above provided template code correctly to your website template file.<head>Area. Next, check if you have filled in the information for this page in the AnQiCMS backgroundCompleteStandard link (for examplehttps://www.yourdomain.com/pageIf only the relative path or an incomplete link is filled in, the system may not be able to identify and output it. Finally, clear the AnQiCMS system cache and check the browser cache.

Q2: Should I set a canonical link for all pages?A2: It is recommended to set a self-referencing standard link for each important page.This helps to avoid potential duplicate content issues and clearly informs search engines of the preferred URL for this page.In cases where there are multiple URLs pointing to the same content, it is essential to make standardized settings.For some pages without actual SEO value (such as user session ID), it can be standardized to a version without parameters.

Q3: What is the difference between Canonical URL and 301 redirect? Which one should I choose?A3: They are all ways to handle duplicate URLs, but their mechanisms are different.

  • Canonical URLIs to make a suggestion to the search engine, telling it which page is the preferred version, but the search engine will still crawl all versions.When a user accesses a duplicate URL, they will stay on that URL page.
  • 301 RedirectIs a permanent server-side command, directly to

Related articles

How to dynamically display SEO title, keywords, and description (TDK) in the page header?

In website operation, the dynamic display of SEO title (Title), keywords (Keywords), and description (Description) at the page header, abbreviated as TDK, is a core element of search engine optimization (SEO).They not only help search engines understand the content of the page, but are also the key to attracting users to click.For users of AnQiCMS, the system provides a powerful and flexible mechanism to implement TDK dynamic management, ensuring that each page can achieve **SEO performance.**

2025-11-08

How to display the website name, Logo, filing number, and copyright information in AnQiCMS templates?

AnQiCMS provides an intuitive and powerful template system that allows us to flexibly display various core information on the website.Whether it is the name of the website, Logo, filing number, or copyright statement, these are all key elements that constitute the brand image of the website, meet compliance requirements, and enhance user trust.This article will delve into how to call and display this information in the AnQiCMS template, ensuring that your website content is complete and professional.

2025-11-08

How to obtain and display the website's friend link list in the template?

Managing and displaying friendship links in AnQiCMS is a very practical feature, whether it is to increase the external links of the website, improve SEO effects, or to facilitate users to access partner websites, it can play an important role.AnQiCMS provides a simple and efficient way for us to easily obtain and display these links in the template.### Step 1: Background Management and Configuration of Friend Links Before displaying the friend links on the website front-end, we need to add and manage them in the AnQiCMS background system

2025-11-08

How to get and display the title, content, link, and thumbnail of a specified single page (such as “About Us”)?

In AnQi CMS, the single-page content of a website such as "About UsThese pages not only need to be displayed under independent URLs, but may also need to extract their titles, summaries, links, or thumbnails in other areas of the website (such as the footer, sidebar, or specific modules on the homepage) for display.Anqi CMS provides simple and powerful template tags, allowing you to easily achieve this requirement in website templates.

2025-11-08

How to enable Markdown editor rendering content on the front-end page and display mathematical formulas and flowcharts?

Content operation plays a crucial role in the digital age today.The strength of a Content Management System (CMS) largely depends on its ability to flexibly support a variety of content presentation forms.AnQiCMS (AnQiCMS) leverages its efficient and flexible features to provide a vast space for content creators.Today, we will delve into how to elegantly enable Markdown editor to create content on the Anqi CMS front-end page, and further realize the rendering of mathematical formulas and flowcharts, making your website content more expressive.###

2025-11-08

How to implement the switching display of multilingual website content and adapt to users of different languages?

Today, with the deepening of globalization, a website that supports multilingualism has become a basic requirement for enterprises to expand into international markets and serve global users.AnQiCMS deeply insight into this trend, providing users with a highly efficient and flexible multilingual website content management solution, helping your website easily switch between different language content display and better adapt to users around the world.The core concept of AnQiCMS implementing multi-language website content switching is based on multi-site management.

2025-11-08

How to dynamically display different group Banner slideshows on the website homepage?

The banner carousel on the homepage is an important window to attract visitors' attention and convey core information.By cleverly setting up, we can allow the home page banner slideshow to dynamically display according to different marketing goals or content themes, which can not only improve user experience but also effectively guide users to browse.AnQiCMS (AnQiCMS) offers flexible features to help users easily meet this requirement.Understanding the Banner mechanism of AnQi CMS In AnQi CMS, the management and display of banners have a clear logic

2025-11-08

How to filter and display articles in a list or category list based on recommended attributes (such as "Top Story

In content management and website operation, how to effectively highlight key information, guide users to focus on specific articles, is the key to improving website effectiveness.AnQiCMS (AnQiCMS) provides a flexible recommendation attribute feature that allows you to easily filter and display articles in article lists or category lists based on attributes such as "Headline" and "Recommended", thus better realizing content operation strategies.

2025-11-08