Nice URLs

When the feature is activated, editors can specify nice URLs and alternate URLs for individual pages, files and images. The nice URL and alternate URLs are additional URLs for a specific page, file or image besides the default URL, which is constructed by concatenating the folder’s publish directory and the object’s filename. It can for example be used as easy to remember short-cut to specially featured objects.

1 Configuration

The feature must be activated

conf/features.yml

feature:
	nice_urls: true

2 Editing

When the feature is activated, additional fields Nice URL and Alternate URLs will be included in the properties dialogs for pages, files and images. The fields may be left empty for objects without nice or alternate URL. If a nice or alternate URL is set, it must begin with a “/” and must not end with a “/”. Invalid URL characters will be sanitized according to the sanitizing file names configuration.

Input that does not comply with these constraints will be corrected automatically.

2.1 Validation

Any input will be sanitized according to the rules for folder paths and will then be made unique (against other nice or alternate URLs or combinations of folder.pub_dir + filename), so that no two objects would be addressed by the same URL.

3 Publishing

To publish an objects’s nice and alternate URLs into the Content Repository, the meta attributes [object].nice_url and [object].alternate_urls must be mapped to attributes (e.g. nice_url and alternate_urls). The attribute alternate_urls must be a multivalue attribute. When publishing into a Mesh Content.Repository, the attributes must be marked as “URL fields”.

See the example implementation in this devtool package: Download nice_urls.zip devtool package

To use the devtool package in your project:

4 Frontend Implementation

The frontend implementation must be able to resolve the nice URL to the object. When using Gentics CMP, this will work out of the box without further configuration using Gentics Mesh Webroot

5 Difference between nice URL and alternate URLs

What is the difference between a nice URL and an alternate URL?

Actually, the only difference is, that the nice URL field can contain only a single value, whereas the alternate URLs field can contain many. This allows to mark one URL (the nice URL) as “special” and frontend implementations could use this “special” URL as the canonical link.

Please consult the guides for Gentics Portal | php or Gentics Portal | Java for details.