AEM CIF Core Components provides advanced configurations to customize the URLs for product and category pages. Many implementations will customize these URLs for search engine optimization (SEO) purposes. The following video details how to configure the UrlProvider
Service and features of Sling Mapping to customize the URLs for product and category pages.
To configure the UrlProvider
service according to the SEO requierments and needs a project must provide a OSGI config for the “CIF URL Provider configuration” configuration, and configure the service as described below.
The Venia Reference store project, see below, includes sample configurations to demonstrate the usage of custom URLs for product and category pages.
This configures the URLs of the product pages with the following properties:
{{page}}.{{url_key}}.html#{{variant_sku}}
, which ends up generating URLs like for example /content/venia/us/en/products/product-page.chaz-kangeroo-hoodie.html#MH01-M-Orange
where
{{page}}
was replaced by /content/venia/us/en/products/product-page
{{url_key}}
was replaced by Magento’s url_key
property of the product, here chaz-kangeroo-hoodie
{{variant_sku}}
was replaced by the currently selected variant, here MH01-M-Orange
SELECTOR
, the other possible value is SUFFIX
. With the previous example URL, this means the identifier chaz-kangeroo-hoodie
will be used to fetch the product data.URL_KEY
, the other possible value is SKU
. With the previous example URL, this means that the product data will be fetched with a Magento GraphQL filter like filter:{url_key:{eq:"chaz-kangeroo-hoodie"}}
.This configures the URLs of the category or product list pages with the following properties:
{{page}}.{{id}}.html
, which ends up generating URLs like for example /content/venia/us/en/products/category-page.3.html
where
{{page}}
was replaced by /content/venia/us/en/products/category-page
{{id}}
was replaced by Magento’s id
property of the category, here 3
SELECTOR
, the other possible value is SUFFIX
. With the previous example URL, this means the identifier 3
will be used to fetch the product data.ID
. With the previous example URL, this means that the category data will be fetched with a Magento GraphQL filter like category(id:3)
.It is possible to add custom properties for each template, as long as the corresponding data is being set by the components using the UrlProvider
. Check for example the code of the ProductListItemImpl
class to find out how this is implemented.
It is also possible to replace the UrlProvider
service with a completely custom OSGi service. In this case, one must implement the UrlProvider
interface and register it with a higher service ranking in order to replace the default implementation.
In addition to the UrlProvider
, it is also possible to configure Sling Mappings in order to rewrite and process URLs. The AEM Archetype project also provides an example configuration to configure some Sling Mappings for port 4503 (publish) and 80 (dispatcher).
URL rewrites can also be achived by using AEM Dispatcher HTTP server with mod_rewrite
module. The AEM Project Archetype provides a reference AEM Dispatcher config which already includes basic rewrite rules for the generated size.
The Venia Reference store project includes sample configurations to demonstrate the usage of custom URLs for product and category pages. This allows each project to setup individual URL patterns for product and category pages according to their SEO needs. A combination of CIF UrlProvider
and Sling Mappings as described above is used.
This configuration must be adjusted with the external domain used by the project. The Sling Mappings are working based on the hostname and domain. Therefore this configuration is disabled by default and must be enabled before deployment. To do so rename the Sling Mapping hostname.adobeaemcloud.com
folder in ui.content/src/main/content/jcr_root/etc/map.publish/https
according to the used domain name and enable this config by adding resource.resolver.map.location="/etc/map.publish"
to the JcrResourceResolver
config of the project.