As an experienced CMS website operation person, I know the key role of website navigation in user experience and search engine optimization.Manage the external links in the navigation well, ensuring they are processed according to our wishes by search engines is an indispensable part of website operation.
Below I will elaborate on how to prevent external links in navigation links from being tracked by search engines in the Anqi CMS.
The significance of external links and search engine tracking
In website operation, we often need to add links to other websites in the navigation, such as partners, related resources, or social media homepages.These external links are crucial for enhancing user experience and providing additional value.However, from the perspective of search engine optimization, too many external links or links to low-quality websites may dilute our website's 'link equity' (Link Juice) and even affect the credibility of the website.To better control the impact of these external links on search engines, we usually want to block search engines from tracking certain specific external links.
Search engines track a link primarily through the process of “crawling” and “transferring link weight”. When we do not want search engines to follow a certain link or transfer link weight to the target website, we can userel="nofollow"This attribute tells the search engine crawler not to consider this link as an endorsement of the target page by the website and not to pass PageRank to the target page.
The default behavior of the AnQi CMS navigation link
The Auto CMS is SEO-friendly in design, providing features such as pseudo-static, 301 redirection, and advanced SEO tools to help improve the website's search engine performance.In terms of content publishing, the "Content Settings" in Anqi CMS includes a feature called "Whether to automatically filter external links.rel="nofollow"Attributes, effectively manage the weight loss of links in the content.
However, the situation is slightly different for website navigation (links configured through "Website Navigation Settings"). The navigation list tags of Anqi CMS (navListIn the template output, there is no field directly provided to controlrel="nofollow"The options of the property. This means that by default, external links added to navigation may be tracked by search engines and pass link weight.
For this reason, we need to take some additional methods to ensure that external links in navigation can also be controlled according to our needs.
Strategy one: Manually add through the template.rel="nofollow"Property
This is the most direct and effective method, by modifying the website's template files, manually adding HTML code for generating navigation linksrel="nofollow"properties.
Confirm the navigation template file:The template files of Anqi CMS are usually located in
/templatethe directory, and organized according to certain conventions (refer to)design-convention.mdanddesign-director.md)。The navigation section is usually in the common code snippet, such aspartial/header.htmlor directly in theindex.html英文中引入。你需要找到使用{% navList navs %}标签来生成导航的那个模板文件。修改模板代码:找到渲染导航链接的
<a>标签。在tag-/anqiapi-other/165.htmlThe example code contains, the structure of the navigation links is roughly as follows:{% navList navs %} <ul> {%- for item in navs %} <li> <a href="{{ item.Link }}">{{item.Title}}</a> {# 可能还有二级导航 #} {%- if item.NavList %} <dl> {%- for inner in item.NavList %} <dd> <a href="{{ inner.Link }}">{{inner.Title}}</a> </dd> {% endfor %} </dl> {% endif %} </li> {% endfor %} </ul> {% endnavList %}To add all external links
rel="nofollow"Firstly, we need to judgeitem.LinkIs it an external link. We can check whether the link ends withhttp://orhttps://starts and does not belong to the current website's domain. At the same time, for security and user experience, it is recommended to add external links withtarget="_blank" rel="noopener noreferrer"Property, ensure that it opens in a new tab and prevents potential security vulnerabilities.You can modify the template code as follows:
{% navList navs %} <ul> {%- for item in navs %} <li> {# 假设 system.BaseUrl 是当前网站的基础URL #} {% set isExternal = (item.Link | startsWith('http://') or item.Link | startsWith('https://')) and not item.Link | contains(system.BaseUrl) %} <a href="{{ item.Link }}" {% if isExternal %}target="_blank" rel="nofollow noopener noreferrer"{% endif %}> {{item.Title}} </a> {%- if item.NavList %} <dl> {%- for inner in item.NavList %} {% set isExternalInner = (inner.Link | startsWith('http://') or inner.Link | startsWith('https://')) and not inner.Link | contains(system.BaseUrl) %} <dd> <a href="{{ inner.Link }}" {% if isExternalInner %}target="_blank" rel="nofollow noopener noreferrer"{% endif %}> {{inner.Title}} </a> </dd> {% endfor %} </dl> {% endif %} </li> {% endfor %} </ul> {% endnavList %}NoteHere:
startsWithandcontainsIs a hypothetical template filter, you need to adjust it according to the actual security CMS template engine supported filters.If not supported, more complex logic or backend support may be required.http://orhttps://If it does not contain your website's domain, it is considered an external link.Use the 'navigation description' field for selective control (recommended practice): if you only want to add part of the external links in the navigation
rel="nofollow",but not all, you can cleverly use the "navigation description" field in the "website navigation settings" of the CMS.- Background operation:In "Background Settings" -> "Website Navigation Settings", edit the one you want to add
nofollowThe navigation link. In the "Navigation Description" field, enter a specific keyword, such asnofollow. - Template modification:Modify in the template file,
<a>Label code, add a conditional judgment to check.item.DescriptionWhether it contains the keywords you set.
{% navList navs %} <ul> {%- for item in navs %} {% set isNofollow = item.Description | contains('nofollow') %} {# 检查描述是否包含 'nofollow' #} {% set isExternal = (item.Link | startsWith('http://') or item.Link | startsWith('https://')) and not item.Link | contains(system.BaseUrl) %} <li> <a href="{{ item.Link }}" {% if isExternal %}target="_blank" rel="noopener noreferrer"{% endif %} {% if isNofollow %}rel="nofollow"{% endif %}> {# 如果描述中包含 nofollow,则添加 #} {{item.Title}} </a> {# 处理二级导航,逻辑类似 #} </li> {% endfor %} </ul> {% endnavList %}This method is more flexible, allowing you to decide whether to add based on the specific link requirements.
nofollow.- Background operation:In "Background Settings" -> "Website Navigation Settings", edit the one you want to add
策略二:利用 Robots.txt (有限的适用场景)
AutoCMS provides advanced SEO tools, including support for Robots.txt configuration (see referencehelp-plugin-rewrite.md)。Robots.txt file is a text file located in the root directory of a website, used to indicate to search engine crawlers which pages can be crawled and which pages cannot be crawled.
However, it should be clear that Robots.txt is mainly used to control search engine crawlers for yourinternal websiteAccess to the page or directory.It cannot directly control the tracking behavior of external links.If you place an external link in navigation, Robots.txt cannot prevent search engines from tracking this link.
Therefore,Robots.txt is not an effective method to block navigation of external links from being tracked.Its purpose is to instruct search engines not to crawl certain sensitive or unimportant internal content on your website (such as admin paths, search result pages, etc.).
Strategy three: Consider future feature enhancements
As an operations personnel, I am well aware of the importance of convenience for daily management. Although it is currently possible to modify templates and utilize existing fieldsnofollow