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, making it more readable and friendly.However, when configuring custom rewrite rules, especially when involving dynamic parameters, improper handling may lead to URL parameter escaping issues, resulting in the page being unable to access normally or the link structure becoming chaotic.

This article will delve into how to correctly configure URL parameters in the custom rewrite rules of AnQiCMS, and provide practical strategies to avoid common escaping issues.

Understand the rules of pseudo-static and URL parameters

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

Path parametersIs to embed dynamic values directly into the URL path, forming something similar to/article/123.htmlor/category/web-design/This structure.AnQiCMS's pseudo-static rules are mainly used to define the format of this path-type parameter.index.php?id=123) into a link that looks like a static HTML file.

Query string parametersThen it is the common one with a question mark?followed bykey=valueYes, multiple parameters are separated by&connected 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 path structure definition of AnQiCMS backend pseudo-static rules, but more in the template construction.

In AnQiCMS, through the background'sFunction management -> URL Rewrite RuleMenu, we can manage these two URL parameters uniformly, where the custom mode provides great flexibility.

AnQiCMS Custom Rewrite Rule Core Mechanism

Custom mode allows us to target document details (archive分类列表(category)、Model Home Page(archiveIndex)、Single Page(page), tag list (tagIndex)and tag details(tagSix core page types, configure their URL structure. Each rule follows规则名===规则值format.

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

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

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

  • {id}: The unique identifier ID for data records.
  • {filename}:数据记录(如文章、单页、标签)的自定义链接别名,通常是拼音或英文。
  • {catname}The custom link alias for categories.
  • {catid}:分类的唯一标识 ID。
  • {module}:内容模型的 URL 别名。
  • {page}Page number.

Correctly configure URL parameters: avoid escaping issues

Escape issues typically occur when the system attempts to process URLs containing special characters or unclear structures. In the custom pseudo-static rules of AnQiCMS, the most common "escape issues" and their solutions revolve around{page}Variables configuration.

The document clearly states,{page}Variables must be placed in parentheses in custom rules.()Inside, for example,(/{page})This is not just a grammatical rule, but also a key to avoiding potential escape issues and implementing URL optionality:

  1. Implement optionality: Through(/{page})This writing, AnQiCMS can identify that the pagination parameters are optional. This means that when the user visits the first page, the URL will not contain/1Such redundant information, but instead directly display a clean URL without pagination parameters. For example, if the rule iscategory===/{catname}(/{page}), then the category URL for the first page might be/news/, and the second page would be/news/2If parentheses are missing, the system may not be able to process correctly/1omitted, resulting in/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 as part of a regular path, especially/Symbol after.Enclose it in parentheses, explicitly indicate to AnQiCMS that this is a potentially existing dynamic fragment for page numbers, and skip it when it does not exist (i.e., on the first page), thus avoiding confusion in path resolution.

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

This rule will generate something like/article/news/(Page 1) and/article/news/2(second page) of the URL, both beautiful and in line with SEO standards.

Except{page}except for special treatment,{filename}and{catname}These custom link aliases also play an important role. They replace the direct use{id}May bring pure digital URL, providing 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, which is a**practical**measure to avoid URL encoding escaping issues.

Practical techniques and precautions to avoid 'escape problems'

To completely avoid the escaping issues in the pseudo-static rule, in addition to following{page}the special syntax

  1. keep custom URL aliases clean: in the background forfilenameorcatnameWhen setting a custom URL for fields, be sure to use only lowercase letters, numbers, and hyphens-or an underscore_Avoid using Chinese characters, spaces,?/&/=//Characters that may lead to URL encoding (escaping). AnQiCMS will try its best to handle them, but manual cleaning can maximize the avoidance of problems.
  2. Distinguish path parameters from query parametersThe pseudo-static rules define thepathpart, not the query string. Do not try to simulate in pseudo-static rules.?