As an experienced website operations expert, I am well aware of the crucial role of Search Engine Optimization (SEO) in the success of a website, and one of the frequently overlooked yet crucial details isCanonical UrlThe correct use. In a powerful content management system like AnQiCMS, we also need to master itstdkTag callCanonicalUrlThe practice of ensuring the uniqueness and authority of website content, thereby achieving better performance in search engines.
What is Canonical URL and why is it so important?
Before we delve into the specific usage of AnQi CMS, it is necessary to understandCanonical UrlThe essence of a normalized URL. Simply put,Canonical UrlIt is an HTML tag<link rel="canonical" href="[URL]"/>and it is placed on the web page's<head>The area is used to tell the search engine: "Although this page can be accessed through multiple URLs or is highly similar to the content of other pages on the website, please concentrate the weight and indexing on the specific canonical URL I specify."
Imagine that your website may have multiple URLs pointing to the same or similar content: for example, the same product page with different tracking parameters (example.com/product?ref=1andexample.com/product?source=ad)、the URL of the same article in different categories(example.com/category1/articleandexample.com/category2/articleOr if your website content is republished on other platforms, search engines may consider it duplicate content.If the search engine cannot determine which is the "official" or "preferred
Canonical UrlThe appearance is to solve this problem.It acts as a clear signpost, explicitly telling search engines which URL is the authoritative version of the content, thereby helping us to consolidate scattered SEO weight, avoid unnecessary duplicate content penalties, and ensure that search engines can correctly index the pages we want to display to users.
Configuration entry for Canonical URL in AnQi CMS
Set in AnQi CMS,CanonicalUrlThe process is intuitive and close to the content management logic.As the core of content management, Anqi CMS allows us to configure the standardized links for each specific document (including articles, products, etc.)When you create or edit an article, a product detail page, or any other document that requires independent SEO management in the background, you will find an input box named "Standard Link" in the "Other Parameters" section of the editing interface.
The document clearly states: "If you want to direct the current document to another page, you need to fill in here.The standard link needs to be called using the canonical tag in the template.This tag may be used on foreign trade websites.https://www.kandaoni.com/article/98.This means that you need to manually fill in this field only when you want the 'main version' of the current page to be different from its own URL.This usually occurs when content is syndicated, or there are indeed multiple URLs pointing to the same content within a website, and you want to explicitly specify a preferred URL scenario.
tdkLabel: The万能钥匙of page SEO
Anqi CMS provides powerful for website front-end templatestdkLabel, it is the all-purpose key for managing page Title, Keywords, Description, and other core SEO elements.The essence of this tag lies in its 'universal' word— it can intelligently extract and output the corresponding TDK information according to the type of the current page (home page, category page, document detail page, etc).CanonicalUrlAs an important part of page SEO, it can also be achieved through thistdkCall the tag.
On the level of template design, we use{% tdk 变量名称 with name="字段名称" %}such syntax to obtain the required information. ForCanonicalUrl, we just need to specifynameparameters for"CanonicalUrl"Just do it.
InvokeCanonicalUrlthe correct posture: template code practice
MasteredCanonicalUrlThe configuration location andtdkAfter the basic usage of the tag, the next is how to call it elegantly and correctly in the front-end template. The most critical principle is:Only when the background is explicitly set for the current pageCanonicalUrlit will be output to the HTML.Avoid outputting empty or unnecessary contentCanonicalUrlTags, which help keep HTML code neat, and avoid ambiguity for search engines.
The following is a call toCanonicalUrlrecommended code practices, usually placed in your website template.<head>Area:
{# 首先,尝试从tdk标签获取CanonicalUrl的值,并将其赋值给名为`canonical`的变量 #}
{%- tdk canonical with name="CanonicalUrl" %}
{# 接着,我们判断这个`canonical`变量是否存在且不为空 #}
{%- if canonical %}
{# 如果存在且不为空,则输出link标签,rel属性为"canonical",href属性为获取到的CanonicalUrl #}
<link rel="canonical" href="{{canonical}}" />
{%- endif %}
The advantage of this code lies in its robustness:
{%- tdk canonical with name="CanonicalUrl" %}This line of code will attempt to retrieve the TDK settings from the current page.CanonicalUrlThe value. If the 'standard link' field is set during the background document editing, it will be assigned tocanonicalthis variable; if not set,canonicalthe variable will be empty.{%- if canonical %}This is a conditional judgment statement, it will checkcanonicalwhether the variable contains valid content. Only whenCanonicalUrlit is explicitly set and a non-empty value is obtained in the background, the code block inside it will be executed.<link rel="canonical" href="{{canonical}}" />: If the condition is met, this line of code will generate standardCanonical Urltags and use{{canonical}}to output the actual normalized link.
In this way, we ensureCanonicalUrlTags are only displayed when necessary, avoiding the output of invalid tags and maintaining the cleanliness of the page and the accuracy of SEO strategy.
In-depth analysis and practical application scenarios
In actual operation,CanonicalUrlNot applicable to all pages, but a SEO tool for specific scenarios.
- Content aggregation and distribution:For example, if you have an original article and you want to publish it on multiple cooperative media platforms. To ensure that search engines know that your website is the 'source', you can include on all转载 pages (including different URL versions that may exist on your own website), that
CanonicalUrlPoint to the original article link on your website. - E-commerce product SKU page:Many e-commerce websites will