This is a library for inserting canonical tags into your pages.
Many sites require content duplication. For example, there can be a sub-tree for each department in the company, where they have their content. However, they may have content which is equal to content in the corporate section.
At the same time, content duplication can greatly affect your ranking. Unfortunately, AEM does not provide flexible way of handling this.
This library provides next features:
- strict mapping, e.g. /path/page1 --(has canonical page)--> /anotherPath/page1
- mapping by the pattern with lookup path, e.g. /path/page[0-9] --(all pages under path have canonical pages)--> /anotherPath
Library has been tested on AEM 6.1 SP1, and JDK 7/8.
Add maven dependency to your project:
<dependency>
<groupId>com.taradevko</groupId>
<artifactId>com.taradevko.aem.seo</artifactId>
<version>0.1.1</version>
</dependency>
Embed bundle into the content package to be installed. It may look like this:
<embedded>
<groupId>com.taradevko</groupId>
<artifactId>com.taradevko.aem.seo</artifactId>
<filter>true</filter>
</embedded>
To build and install bundle to your AEM instance, use next command (host/port values should be adjusted to the values you have):
mvn clean install -PautoInstallBundle -Daem.host=localhost -Daem.port=4502
After bundle installed, next steps should be performed:
- Create system user, grant required permissions to it and configure it for the bundle com.taradevko.aem.seo:
- Configure service Canonical Tagging Support (pid com.taradevko.aem.seo.service.CanonicalTaggingImpl). Via Web Console/sling:OsgiConfig:
Rule has next syntax:
- for strict rules, where page is mapped to another page:
_PATH PAGE 1_=>_CANONICAL PAGE PATH_
- for rules which map pages by regex and provide lookup path:
_PATTERN FOR PAGE WHICH CHILD WILL BE MAPPED_>_LOOKUP PATH_
- Add canonical tag to your . To do this: insert next code into the required place:
<link data-sly-use.canonicalTagging="com.taradevko.aem.seo.CanonicalLinkModel" data-sly-test="${canonicalTagging.hasCanonicalPage}" rel="canonical" href="${canonicalTagging.canonicalUrl}.html" />
- Make sure, that externalizer is configured. Also, you can additionally configure URL Mappings in Resource Resolver Factory, to omit some part of the path in URL.
Page structure:
Having configuration and structure, how it is shown above, we will get next results:
- strict rule
- pattern rule
- pattern rule with url mapping
The Apache License (Version 2.0, January 2004).