As an experienced security CMS website operator, I am well aware of the key role of website navigation in user experience and search engine optimization.Manage external links well in the navigation, ensuring they are processed according to our wishes by search engines is an indispensable aspect of website operation.
I will elaborate in detail on how to prevent external links in navigation links from being tracked by search engines in 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 pages.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 external links pointing to low-quality websites may dilute the "link equity" (Link Juice) of our website and even affect its reputation.To better control the impact of these external links on search engines, we would usually want to prevent search engines from tracking certain specific external links.
The search engine tracks a link mainly through the two processes of 'crawling' and 'transmitting link weight'. When we do not want the search engine to follow a link or pass link weight to the target website, we can userel="nofollow"The attribute tells the search engine crawler not to consider the link as an endorsement by the website of the target page, and not to pass PageRank to the target page.
Default behavior of AnQi CMS navigation link
The Anqi CMS is SEO-friendly in design, providing features such as static URLs, 301 redirects, and advanced SEO tools to help improve the website's search engine performance.In terms of content publishing, Anqi CMS's "Content Settings" includes a feature named "Whether to automatically filter external links".When this feature is enabled, external links inserted into the content of articles or pages will be automatically addedrel="nofollow"The attribute effectively manages the link weight loss in the content.
However, for website navigation (configured links through "website navigation settings"), the situation is somewhat different. The Anqi CMS navigation list label (navListIn the template output, there is no field provided directly to controlrel="nofollow"The option of the attribute. This means that by default, external links added to the navigation may be tracked by search engines and pass link weight.
For this reason, we need to take some additional methods to ensure that the external links in the navigation can also be controlled according to our needs.
Strategy one: Add manually through the template.rel="nofollow"property
This is the most direct and effective method, by modifying the website template files, manually adding navigation link HTML code in the generated navigation links.rel="nofollow"Property.
Confirm navigation template file: The template files of AnQi CMS are usually located
/templatein the directory, and organized according to certain conventions (refer todesign-convention.mdanddesign-director.md)。The navigation section is usually in the public code snippet, such aspartial/header.htmlor directly inindex.htmlintroduce. You need to find the one using{% navList navs %}label to generate the template file for navigation.Modify the template code:Find the rendered navigation link of
<a>tag.tag-/anqiapi-other/165.htmlIn the example code, the structure of the navigation link 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 %}Add to all external links
rel="nofollow"First, we need to determine,item.LinkIs it an external link. We can check if the link starts withhttp://orhttps://Start, and it does not belong to the current website domain to judge. At the same time, for security and user experience, it is recommended to add external links.target="_blank" rel="noopener noreferrer"Attribute, ensure that it opens in a new tab and prevents potential security vulnerabilities.You can modify the template code in the following way:
{% 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 is the
startsWithandcontainsIt is a kind of template filter assumption, you need to adjust according to the actual filter supported by the safe CMS template engine.If not supported, it may require more complex logic or backend support.A more general way to judge is, if the link containshttp://orhttps://If it does not contain the domain name of your website, it is considered an external link.Utilize the "navigation description" field for selective control (recommended practice) If you only want to add some external links in the navigation
rel="nofollow"Instead of all, it can be cleverly utilized by taking advantage of the 'Navigation Description' field in the 'Website Navigation Settings' of AnQi CMS.- Background operation:In the "Background Settings" -> "Website Navigation Settings" section, edit the links you want to add
nofollowNavigation links. In the "Navigation Description" field, enter a specific keyword, such asnofollow. - Template modification:Modify in the template file,
<a>Add a conditional check to the tag code,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 approach is more flexible, allowing you to decide whether to add it based on the specific link's needs
nofollow.- Background operation:In the "Background Settings" -> "Website Navigation Settings" section, edit the links you want to add
Strategy two: Use Robots.txt (Limited application scenarios)
AnQi CMS provides advanced SEO tools, including support for Robots.txt configuration (refer to thehelp-plugin-rewrite.mdThe Robots.txt file is a text file located in the root directory of a website, used to instruct search engine crawlers which pages can be indexed and which pages cannot be indexed.
However, it should be clearly stated that Robots.txt is mainly used to control search engine crawlers on yourInternal websitePage or directory access. It cannot directly control the tracking behavior of external links.If you place an external link in the navigation, Robots.txt cannot prevent search engines from following this link.
Therefore,Robots.txt is not an effective method to prevent navigation from tracking external links.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 fields to achieve thisnofollow