Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The mappings are delegated to a separate module ( virtual-uri ) through the  the info.magnolia.virtualuri.VirtualUriFilter  class  class and are stored in their own registry (VirtualUriRegistry ), which allows to reference each mapping also in YAML definition files. All virtual URI mappings can be located via the Definitions app no matter whether they come from JCR or a YAML file:

...

  • Web pages have moved due to site re-organization. Users still have old URLs in their bookmarks and in search engine indexes. Without redirection traffic would be lost.
  • Registering alternative domain extensions like example.net and example.org and redirecting them to your primary site example.com . You can map multiple domain names to a site in your Magnolia site definition. This can be a major time-saver for a CMS team since there is no need to configure a Web server. Note that you need to register the domains with a registrar first and make sure that DNS entries for the domains point to the server hosting your Magnolia instance.

As an example of mapping, see also Turning a template-based JSON provider into a RESTful API with virtualURIMapping where we define a custom virtual mapping to rewrite a path like /getjson/tours/magnolia-travels/Kyoto  into  into /getjson?workspace=tours&path=/magnolia-travels/Kyoto.

...

Info

Please note that the YAML-based configuration must be stored under the   virtualUriMappings folder, with the plural -s at the end and camel-cased Uri in the middle of the name of the folder. In JCR configuration, the node's name can be either virtualUriMappings or the older virtualURIMapping. In either case make sure that the folder is at the top level inside module configuration.

Multiexcerpt include
MultiExcerptNametooManyURImappings
PageWithExcerpt_Known issues

...

Example: A mapping named enterprise-edition forwards users from example.com/ee to example.com/enterprise-edition . The DefaultVirtualUriMapping class (for description see the Mapping classes section below) maps one URI to another. This ensures that external links that point to example.com/ee still work when the target page is renamed.

...

  • info.magnolia.virtualuri.mapping.*
    • Javadoc resource link
      classNameinfo.magnolia.virtualuri.mapping.DefaultVirtualUriMapping
      renderTypeasynchronous
       maps a virtual URI to a content path. This is the simplest and most common type.
      If the URI starts with a dot ( . ), it is not taken as a wildcard anymore but the dot in fact is interpreted as dot. If you need a wildcard, use ? instead.
    • Javadoc resource link
      classNameinfo.magnolia.virtualuri.mapping.RegexpVirtualUriMapping
      renderTypeasynchronous
       allows you to specify a regular expression pattern that matches a sequence of characters. A regexp pattern can match a variety of URIs, which saves time and effort as you would otherwise have to create default mappings for each case. toUri can contain back references to the regexp matches.
    • Javadoc resource link
      classNameinfo.magnolia.virtualuri.mapping.RotatingVirtualUriMapping
      renderTypeasynchronous
       is an extension of RegexpVirtualUriMapping that allows rotation between different destination URIs. In order to rotate, toUri must contain an asterisk character * that will be replaced by a random integer between start (default is 1) and end minus one (default is 3). An additional property padding specifies the desired width of the string. Zeroes are added to the left of the integer to make all strings equally wide. Default width is 2.

    • Javadoc resource link
      classNameinfo.magnolia.virtualuri.mapping.HostBasedVirtualUriMapping
      renderTypeasynchronous
       forwards the request to a different URI depending on the requested host name.
    • Javadoc resource link
      classNameinfo.magnolia.virtualuri.mapping.HostBasedRegexpVirtualUriMapping
      renderTypeasynchronous
       combines the host-based and regex mappings, i.e. forwards the request to a different URI depending on the requested host name and allows you to specify a regular expression pattern that matches a sequence of characters.
  • info.magnolia.multisite.mapping.* 
    • Javadoc resource link
      classNameinfo.magnolia.multisite.mapping.MultiSiteRootVirtualUriMapping
      renderTypeasynchronous
       is a special class which specifies the root of a site if site matching returns null. 
    • Javadoc resource link
      classNameinfo.magnolia.multisite.mapping.MultiSiteRegexpVirtualUriMapping
      renderTypeasynchronous
       adds a site condition to the mapURI check.  A A mapping will only match the request if both the specified regular expression and the specified site match.

...

The patterns for regular expressions in the regex-based classes are defined in java.util.regex.Pattern .

Action prefixes

You can use these action prefixes:

...

It is also possible to leave the action prefix out. A virtual URI mapping that does not have a prefix does not re-process the request. It just changes the current URI in the 

Javadoc resource link
classNameinfo.magnolia.cms.core.AggregationState
renderTypeasynchronous
 .

Examples

Default

Forward from /winter2016 to /marketing/campaigns/winter2016 .

Advanced Tables - Table Plus
heading0
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse

Node name

Value

Mgnl f
virtualUriMappings


Mgnl n
winter2010


Mgnl p
class

info.magnolia.virtualuri.mapping.DefaultVirtualUriMapping

Mgnl p
fromUri

/winter2016

Mgnl p
toUri

forward:/marketing/campaigns/winter2016

...

A request URI such as forward:/banner/image_*.jpg will randomly forward the request to /banner/image_01.jpg /banner/image_02.jpg or /banner/image_03.jpg . A use case for this class is rotating images such as banner ads. The mapping displays a random ad on each page visit.

...

Forward the visitor to a German language version of the home page when the site is requested with the .de country domain. Similarly, forward to a French version when the site is requested with the .fr country domain. The matching pattern is in the host property. The toUri value under the parent node works as a fallback option. If no hostname match is found, such as when the site is requested with acme.com , forward to an English version.

...