In website operation, the structure of URL (Uniform Resource Locator) is crucial for search engine optimization (SEO) and user experience.AnQiCMS provides flexible pseudo-static features, allowing us to customize the website URL format to make it more readable and friendly.However, when configuring custom pseudo-static rules, especially when involving dynamic parameters, improper handling may lead to URL parameter escaping issues, resulting in the page not being accessible normally or the link structure becoming chaotic.

This article will delve into how to correctly configure URL parameters in AnQiCMS's custom static rules and provide practical strategies to avoid common escaping issues.

Understand the rules of pseudo-static and URL parameters

Firstly, we need to distinguish between the two main ways of passing URL parameters: path parameters and query string parameters.

Path parametersIt refers to embedding dynamic values directly into the URL path, forming something similar/article/123.htmlor/category/web-design/Such a structure. The pseudo-static rules of AnQiCMS are mainly used to define the format of path parameters.They will originally dynamic, with question marks and equal signs URL, such asindex.php?id=123) to look like a static HTML file link.

Query string parametersIt is a common format ending with a question mark?Starting with, followed bykey=valueYes, multiple parameters are separated by&Connected in the format, such as/search?q=AnQiCMS&page=2. This type of parameter is usually used for search, filtering, or pagination scenarios, and is not directly affected by the AnQiCMS backend pseudo-static rules path structure definition, but more in the template construction.

In AnQiCMS, through the background,Function Management -> Static RuleMenu, we can manage these two URL parameters uniformly, where the custom mode provides great flexibility.

The core mechanism of AnQiCMS custom static rules

AnQiCMS is built-in with a variety of predefined static URL patterns such as numeric patterns, model naming patterns, etc., which usually meet most basic needs.But when we pursue a more unique URL structure or encounter a specific scenario, the custom pattern becomes particularly important.

The custom mode allows us to target document details(archive), category lists(category), model home page (archiveIndex)、Single page(page), tag list(tagIndex) and tag details(tagSix core page types, configure their URL structure separately. Each rule follows规则名===规则值format.

For example, a basic article detail rule might look something like this:archive===/{module}/{id}.html

This rule indicates that the URL of the article detail page will be/模块别名/文章ID.htmlcomposed of.

In the rule value, AnQiCMS provides a series of available variables, which are the foundation for building dynamic URLs:

  • {id}: The unique identifier ID of the data record.
  • {filename}The custom link alias for data records (such as articles, single pages, tags), usually pinyin or English.
  • {catname}Custom link alias of the category.
  • {catid}The unique identifier ID for categories.
  • {module}The URL alias for content models.
  • {page}Page number.

Properly configure the key variables of URL parameters: avoid escaping issues

Escape issues usually occur when the system attempts to process URLs that contain special characters or unclear structures. The most common "escape issues" and their solutions in AnQiCMS's custom static rules revolve around{page}The configuration of the variable.

The document clearly states,{page}The variable must be placed in parentheses in the custom rule()for example,(/{page})This is not just a grammatical rule, but also the key to avoiding potential escaping problems and implementing URL optionality:

  1. Implement optionality: Pass(/{page})This style, AnQiCMS can identify that the pagination parameter is optional. This means that when the user visits the first page, the URL will not appear/1Such redundant information, but directly display a clean URL without pagination parameters. For example, if the rule iscategory===/{catname}(/{page}), then the category URL for the first page may be/news/, and the second page will be/news/2If brackets are missing, the system may not process correctly/1Omission may result in generation/news/1Such redundant links, or path matching issues may occur during parsing.

  2. Avoid unexpected path matching and parameter parsingWithout parentheses:{page}May be incorrectly parsed by the system as part of a regular path, especially in/After the symbol. Enclose it in parentheses to clearly indicate to AnQiCMS that this is a potentially existing dynamic fragment for page numbers, and if it does not exist (i.e., the first page), it should be skipped to avoid confusion in path resolution.

For example, a common and correct classification list static rule is as follows:category===/{module}/{catname}(/{page})

This rule will generate something similar/article/news/(Page 1) and/article/news/2(second page) URL, both beautiful and SEO compliant.

except{page}except for special processing, {filename}and{catname}These custom link aliases also play an important role. They replace direct usage{id}A pure numeric URL that provides more semantic and keyword-rich links.When editing documents, categories, or tags in the background, we can specify URL-friendly aliases for them in the "Custom URL" field (usually lowercase letters, numbers, and hyphens), and the system will also automatically generate pinyin aliases as default values.Ensure that these custom URLs do not contain spaces, Chinese characters, or other special characters, as it is a practice to avoid URL encoding escaping issues.

Practical techniques and precautions to avoid 'escape issues'

Completely avoid the escaping problem in the pseudo-static rule, in addition to following{page}special syntax, there are also some general practical skills:

  1. Keep the custom URL alias clean: In the background forfilenameorcatnameWhen setting a custom URL for a field, be sure to use only lowercase letters, numbers, and hyphens-or underscores_. Avoid using Chinese characters, spaces, and other symbols.?/&/=//Characters that may cause URL encoding (escaping). AnQiCMS will try its best to handle them, but manual cleaning can help avoid problems to the maximum extent.
  2. Differentiate between path parameters and query parameters: The static routing rule defines thepathpart, not the query string. Do not attempt to simulate in the static routing rule?