In website operation, Search Engine Optimization (SEO) is a key element in enhancing website visibility and attracting targeted user traffic.Among them, how to effectively handle duplicate content and normalize URLs is an important detail that should not be overlooked in SEO strategy.AnQiCMS (AnQiCMS) is a system designed for content operation teams and provides powerful and flexible functional support in this aspect.This article will discussCanonicalUrlHow to work together with the URL parameter escaping feature in AnQiCMS to optimize the website's SEO performance.

The core value of the canonical link (CanonicalUrl) in SEO

Firstly, we need to understandCanonicalUrlThe role of the specification link. When there are multiple pages on a website with identical or extremely similar content (such as pages tracked through different channels, pages with sorting or filtering parameters, and print versions, etc.), search engines may treat them as duplicate content, which not only distributes the page authority, but may also affect the overall ranking of the website.The purpose of the canonical link is to inform search engines: 'This URL is the preferred version of this page's content, please concentrate all weight and signals to this URL.'

In AnQiCMS, setting up standard links is an intuitive and important operation.In the document or page editing interface of the content management backend, there is usually a dedicated field that allows you to specify a standard link for the page.This link should point to the 'cleanest' URL version you want search engines to index and rank.For example, your product list page may be generated due to different sorting methodsproduct.html?sort=price_ascandproduct.html?sort=price_descMultiple URLs exist, but their core content is consistent. At this point, you can set the standard links of these two pages toproduct.html.

In the template, AnQiCMS providestdkLabels for convenient output of standard links. You can use the following code on the<head>area:

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

This code will first check if a specification link is set for the current page, and if it is set, it will generate it in the HTML<link rel="canonical">Label, clearly indicate the preferred URL of the page to search engines.

URL parameter escaping: eliminate SEO risks.

URL parameters are very common on websites, they can implement various dynamic functions, such as tracking user sources, filtering products, page sorting, etc.However, these parameters also bring SEO challenges. Search engine crawlers encounterexample.com/page?id=123&source=baiduandexample.com/page?id=123When, it may be considered as two different pages, which may lead to duplicate content issues.In addition, parameters containing special characters, if not handled correctly, may also cause URL structure confusion and affect the efficiency of web crawling.

AnQiCMS provides a static URL feature that can convert dynamic URLs into more semantically and SEO-friendly forms, such asexample.com/category/article-title.htmlThis greatly reduces the impact of parameters on the URL.However, in certain scenarios where parameters must be used, or when dynamically constructing links with parameters in templates, it is particularly important to ensure the correct escaping of parameters.

AnQiCMS's template engine is built-in withurlencodeandiriencodeEscaping filters, used to handle URL parameter escaping.

  • urlencodeThe filter will encode all special characters in the URL with percentage encoding (for example, spaces become)%20,&changes to%26This ensures that URLs are correctly parsed in different systems and browsers, avoiding URL parsing errors or security issues due to special characters.

    {{ "http://www.example.org/foo?a=b&c=d"|urlencode }}
    {# 显示结果: http%3A%2F%2Fwww.example.org%2Ffoo%3Fa%3Db%26c%3Dd #}
    
  • iriencodeThe filter is more focused on the encoding of Internationalized Resource Identifiers (IRI), it will encode the URL parameters except for/#%[]=:;$&()+,!?*@'~These characters other than the common URL components are encoded. It is usually used to handle URL paths or query strings containing non-ASCII characters (such as Chinese).

    {{ "?foo=123&bar=yes"|iriencode }}
    {# 显示结果: ?foo=123&amp;bar=yes #}
    

When you dynamically generate links in a template, and the link parameters may contain user input or complex data extracted from a database, using these escape filters is**practical.

CanonicalUrl and URL parameter escaping collaboration

CanonicalUrl and URL parameter escaping are not independent operations in optimizing SEO but work together to provide clear and accurate signals to search engines.

Imagine a scenario: You have a product detail page with a specification linkhttps://yourdomain.com/products/awesome-product.htmlHowever, there may be some internal links on this page to filter different colors or sizes of the product, such ashttps://yourdomain.com/products/awesome-product.html?color=red&size=large.

In this case:

  1. The function of CanonicalUrl:It explicitly tells search engines, regardless of whether users access?color=redOr other parameter access, all these pages with parameters should be classified ashttps://yourdomain.com/products/awesome-product.htmlThis is a specification page. This avoids duplicate content issues and concentrates SEO weight.

  2. The purpose of URL parameter escapingWhen you generate in a template?color=red&size=largesuch an internal link, ifcolororsizethe value itself may contain special characters (such as,color=深蓝&型号=X L), then useurlencodeThe filter escaping these parameter values becomes crucial.

    {% set base_url = "/products/awesome-product.html" %}
    {% set color = "深蓝" %}
    {% set size = "X L" %}
    <a href="{{ base_url }}?color={{ color|urlencode }}&size={{ size|urlencode }}">查看深蓝XL款</a>
    

    This ensures that the generated link is valid and will not be incorrectly identified or parsed by search engines due to special characters, thereby affecting the crawling of internal links.

Although CanonicalUrl is mainly used to declare the preferred version of a page, if it is constructed based on dynamic parameters due to certain special requirements (although it is not recommended, it may exist in extreme cases), then ensure that any dynamic parameters in the canonical URL are properly escaped to ensure its own validity and that search engines can correctly understand it.

In short, AnQiCMS providesCanonicalUrlsettings andurlencode/iriencodeParameter escaping function is a pair of sharp tools for website operators in refined SEO management.The standard link specifies the direction for search engines, and parameter escaping ensures the health and clarity of the internal link structure of the website.The combination can effectively solve SEO problems such as duplicate content and low crawling efficiency, thereby improving the website's performance in search engines.

Frequently Asked Questions (FAQ)

1. Since pseudo-static has been used, why is it still necessary to set CanonicalUrl?The static pseudonymization mainly optimizes the URL structure, making it more readable and SEO-friendly, but it cannot completely avoid the generation of duplicate content. For example, through advertising tracking links (yourdomain.com/page?utm_source=ad)、Different sorting / filtering parameters(yourdomain.com/page?sort=date)or user session ID(`yourdomain.com/page?sessionid