In website operation, a clear and standardized URL is crucial for search engine optimization (SEO) and user experience.AnQiCMS (AnQiCMS) provides a flexible custom URL alias feature, allowing us to optimize the link structure according to our needs./Parentheses or hyphen (-These symbols may cause the URL to be unattractive and may even affect the SEO standards in some cases.
Understanding the custom URL alias mechanism of Anqi CMS
In Anqi CMS, whether it is to publish documents, manage categories, create single pages, or set tags, we can set a 'custom URL' for them.This custom URL alias is a key part of the final access link.The system usually generates a pinyin alias based on the content you enter (such as the title), but you can also manually modify it as needed.
For example, when you are editing a document, you will see an 'Custom URL' input box. Here, enter a string such asmy-article-titleIt will be combined with the module name, ID, and others under the action of pseudo-static rules to form the final access link, for exampleyourdomain.com/article/my-article-title.html.Anqi CMS explicitly states that custom URL aliases should mainly consist of letters, numbers, and underscores, and ensure uniqueness throughout the entire site.This means that slashes or excessive hyphens should not usually be part of the alias content.
Why do we need to refine the handling of symbols at the end of URL aliases?
Although AnQi CMS handles most URL normalization issues when generating the final access link, custom URL aliases, as a user-controlled element, may still introduce some subtle irregularities, especially at the end of the alias.
Firstly, fromSEOViewing from the perspective ofyourdomain.com/article/my-article-title-/andyourdomain.com/article/my-article-title.htmlMay be considered as two different pages by search engines, causing duplicate content issues.Although it can be solved by setting up 301 redirects or Canonical tags, it is better to keep the URL simple and consistent from the source.
secondly,User ExperienceIt is also a consideration.A clean URL without extra symbols looks more professional, easier to remember, and share.When a user sees extraneous characters at the end of a URL alias, they may feel confused.
Therefore, even the subtle special symbols at the end of aliases are worth our attention and handling to ensure the state of the website URL structure.
Using AnQi CMS template filters for elegant processing
The Anqi CMS template engine is powerful and flexible, supporting filters similar to Django template syntax, which provides us with the opportunity to optimize URL aliases at the display level without modifying the original database data. For removing the special symbols at the end of the custom URL alias, trimRightThe filter is an ideal choice.
trimRightThe filter is specifically used to remove a specified set of characters from the end of a string.Its strength lies in its ability to only process characters at the end of a string without touching any content in the middle, which perfectly fits our needs.
UsetrimRightThe basic syntax of the filter is:
{{ 变量名|trimRight:"要移除的字符集合" }}
Suppose we have a nameditem.TokenThe variable that stores the original string of the custom URL alias, and we want to remove the trailing slash (/) and hyphen (-)
Specific operation steps (to be implemented in the template):
- Identify the target alias variable:In the Anqi CMS template, custom URL aliases are usually stored in