Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
HTML Wrap
alignright
classmenu

Related topics:

Virtual URI mapping is a way to redirect an incoming request to the actual location of the content. Typically the virtual address does not match the site hierarchy exactly. 

...

The URIs can be either absolute or relative within the web application in which case the context path is added automatically. For example:

Info

It's important to keep in mind the placement of the virtualURIFilter in the chain. The filter acts on the current URI at the time of execution. Any selectors removed from the current URI before the filter executes cannot be configured in fromUri. For example, langauge selectors would be removed from the current URI before the filter executes.

  • Relative

    fromUri: /winter2016
    toUri: forward:/marketing/campaigns/winter2016
  • Relative
    fromUri: /winter2016
    toUri: forward:/marketing/campaigns/winter2016Absolute

    fromUri: /winter2016
    toUri: forward:https://www.example.com/marketing/campaigns/winter2016.html

The mappings registry

Mappings The mappings are delegated to a separate module ( virtual-uri ) through the  info.magnolia.virtualuri.VirtualUriFilter  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:

You can also check the mappings in the About app's Virtual URI Mappings tab, or by searching Alternatively, search the config space with the JCR browser app:

Image RemovedImage Added

Where to use virtual mappings

...

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

Node name

Value

Mgnl f
<my-module>


Mgnl f
virtualUriMappings


Mgnl n
enterprise-edition


Mgnl p
class

info.magnolia.virtualuri.mapping.DefaultVirtualUriMapping

Mgnl p
fromUri

/ee

Mgnl p
toUri

forward:/enterprise-edition

Via YAML

((warning) Magnolia 5.5.6+) You You can configure virtual URI mappings in a YAML definition file inside a light module folder:

...

class

required

Class that performs the mapping. See the section Mapping classes below.

fromUri

required

Pattern to match in the requested URI.

toUri

required

Concrete URI where the request is mapped to.

site

required (for the MultiSiteRegexpVirtualURIMapping MultiSiteRegexpVirtualUriMapping class)

Specifies the site that should be used for the mapping.

Info

Please be aware that with Magnolia 5.5.6+, the case of the fromUri and toUri properties has changed. The original pre-5.5.6 uppercase forms ( fromURI and toURI ) have been deprecated and will work only when used together with the deprecated classes.

A catalog of mappings

((warning) Magnolia 5.5.6+) For easier orientation, if you have to configure a lot of mappings, you can store them in folder-like structures rather than in one long flat list of mappings:

A catalog of mappings

For easier orientation, if you have to configure a lot of mappings, you can store them in folder-like structures rather than in one long flat list of mappings:

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

Node name

Value

Mgnl f
<my-module>


Mgnl f
virtualUriMappings


Mgnl n
europe


Mgnl p
class

info.magnolia.virtualuri.mapping.DefaultVirtualUriMapping

Mgnl p
fromUri

/customer-support-europe.html

Mgnl p
toUri

forward:/europe/cust-support.html

Mgnl n
usa


Mgnl p
class

info.magnolia.virtualuri.mapping.DefaultVirtualUriMapping

Mgnl p
fromUri

/customer-support-usa.html

Mgnl p
toUri

forward:/usa/cust-support.html

Mgnl n
asia-australia


Mgnl n
asia


Mgnl p
class

info.magnolia.virtualuri.mapping.DefaultVirtualUriMapping

Mgnl p
fromUri

/customer-support-asia.html

Mgnl p
toUri

forward:/asia/cust-support.html

Mgnl n
australia


Mgnl p
class

info.magnolia.virtualuri.mapping.DefaultVirtualUriMapping

Mgnl p
fromUri

/customer-support-australia.html

Mgnl p
toUri

forward:/australia/cust-support.html

...

Magnolia provides eight ready-made classes that perform virtual URI mapping:

  • info.magnolia.virtualuri.mapping.* 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.
    ((warning) Magnolia 5.4.6+) 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
      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.HostBasedRegexpVirtualUriMappingRegexpVirtualUriMapping
      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
      asynchronous
       allows you to specify a regular expression pattern that matches a sequence of characters.
    info.magnolia.module.googlesitemap.config.mapping.*
    • 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.

      module.googlesitemap

      virtualuri.

      config.

      mapping.

      SiteMapVirtualUriMapping

      RotatingVirtualUriMapping
      renderTypeasynchronous

      compares source URI to names of sitemaps available in the googleSitemaps workspace and prepends the prefix.
    info.magnolia.multisite.mapping.* 
    •  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.multisitevirtualuri.mapping.MultiSiteRootVirtualUriMappingHostBasedVirtualUriMapping
      renderTypeasynchronous
       is a special class which specifies the root of a site if site matching returns null forwards the request to a different URI depending on the requested host name.
    • Javadoc resource link
      classNameinfo.magnolia.multisitevirtualuri.mapping.MultiSiteRegexpVirtualUriMappingHostBasedRegexpVirtualUriMapping
      renderTypeasynchronous
       adds a site condition to the mapURI check.  A mapping will only match the request if both the specified regular expression and the specified site match.

  You can also write your own implementation.

...

Deprecated classes

...

    •  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.module.googlesitemap.config.mapping.*
    • Javadoc resource link
      asynchronous
      classNameinfo.magnolia.module.googlesitemap.config.mapping.SiteMapVirtualUriMapping
      renderTypeasynchronous
      compares source URI to names of sitemaps available in the googleSitemaps workspace and prepends the prefix.
  • info.magnolia.multisite.mapping.* 
    • Javadoc resource link
      classNameinfo.magnolia.multisite.MultiSiteRootVirtualURIMapping
      renderTypeasynchronous
      Javadoc resource link
      classNameinfo.magnolia.multisite.MultiSiteRegexpVirtualURIMappingmapping.MultiSiteRootVirtualUriMapping
      renderTypeasynchronous

With the introduction of the virtual-uri module in Magnolia 5.5.6, the following classes have been deprecated:

  • info.magnolia.cms.beans.config.*
    •  is a special class which specifies the root of a site if site matching returns null
    • className
      Javadoc resource link
      rangeHigherVersion5.5.6
      classNameinfo.magnolia.cms.beans.config.DefaultVirtualURIMapping
      renderTypeasynchronous
      Javadoc resource link
      rangeHigherVersion5.5.6
      classNameinfo.magnolia.multisite.mapping.MultiSiteRegexpVirtualUriMapping
      renderTypeasynchronous
       adds a site condition to the mapURI check.  A mapping will only match the request if both the specified regular expression and the specified site match.

You can also write your own implementation.

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

Anchor
deprecated-classes
deprecated-classes

Deprecated classes

The following classes have been deprecated with the release of Magnolia 5.6:

  • info.magnolia.cmsmodule.beansgooglesitemap.config.*
      RegexpVirtualURIMappingrenderTypeasynchronous
    • 5.5.6
      Javadoc resource link
      rangeHigherVersion
      classNameinfo.magnolia.cmsmodule.beansgooglesitemap.config.RotatingVirtualURIMappingSiteMapVirtualUriMapping
      renderTypeasynchronous
  • info.magnolia.multisite.*
    • 5.5.6
      Javadoc resource link
      rangeHigherVersion
      classNameinfo.magnolia.cms.beans.config.HostBasedVirtualURIMappingmultisite.MultiSiteRootVirtualURIMapping
      renderTypeasynchronous
    • rangeHigherVersion
      Javadoc resource link
      5.5.6classNameinfo.magnolia.cms.beans.configmultisite.HostBasedRegexpVirtualURIMappingMultiSiteRegexpVirtualURIMapping
      renderTypeasynchronous

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

...

.magnolia.virtualuri.mapping.DefaultVirtualUriMapping

Mgnl p
fromUri

/winter2016

Mgnl p
toUri

forward:/marketing/campaigns/winter2016

Regular expression

Info
iconfalse

(warning) Always test your regex-based virtual URI configurations thoroughly before applying them to a live environment. The configurations that seem correct on the surface can yield unwanted results. For example, using boundary matchers (the hat ^, the dollar $, and others) in fromUri and toUri may improve your matches otherwise a simple value such as /foobar.html will be matched not only in /foobar.html but also in /something/foobar.html.

Take requested page name and pass it as a productId request parameter to a product detail page.

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

Node name

Value

Mgnl f
virtualUriMappings


Mgnl n
productIDs


Mgnl p
class

info.magnolia.virtualuri.mapping.RegexpVirtualUriMapping

Mgnl p
fromUri

/products/([0-9A9a-zA-Z-]+)\.html

Mgnl p
toUri

forward:/product/detail.html?productId=$1

The pattern [0-9a-9AzA-Z-] in fromUri means "any single character in the range of 0-9 or a-z or A-Z or the character - literally". The plus character makes this a greedy pattern that matches one or more of the preceding token, and will match as many characters as possible before satisfying the next token. By enclosing the pattern in parentheses we create a capturing group ([0-9a-9AzA-Z-]+]) which can be referenced in the toUri using $1.

...

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

Node name

Value

Mgnl f
virtualUriMappings


Mgnl n
language-by-domain


Mgnl n
mappings


Mgnl n
de


Mgnl p
host

travel.de

Mgnl p
toUri

forward:/de/travel

Mgnl n
fr


Mgnl p
host

travel.fr

Mgnl p
toUri

forward:/fr/travel

Mgnl p
class

info.magnolia.virtualuri.mapping.HostBasedVirtualUriMapping

Mgnl p
fromUri

/

Mgnl p
toUri

forward:/en/travel

Anchor
GoogleSitemapVirtualUriMapping
GoogleSitemapVirtualUriMapping
Google Sitemap

The mapping redirects the requests for sitemaps to the /sitemaps node. The configuration is taken from the google-sitemap module in the default installation of Magnolia:

Advanced Tables - Table Plus
heading0
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
redirect:/sitemaps

Node name

Value

Mgnl f
virtualUriMappings


Mgnl n
siteMaps


Mgnl p
class

info.magnolia.module.googlesitemap.config.mapping.SiteMapVirtualUriMapping

Mgnl p
prefix

.mapping.SiteMapVirtualUriMapping

Mgnl p
prefix

redirect:/sitemaps

Properties:

class

Javadoc resource link
classNameinfo.magnolia.module.googlesitemap.config.mapping.SiteMapVirtualUriMapping
renderTypeasynchronous
compares source URI to names of sitemaps available in googleSitemaps workspace and prepends the prefix.

prefix

Prefix prepended by the class.


Mappings in the default installations of Magnolia

DefaultVirtualUriMapping

((warning) This is an old mapping and
will be soon removed from the default mappings.)

ModuleEdition

Mapping class

From

(Site)

ToactivationCE, EE
/ActivationHandlerforward:/.magnolia/activation

ui-admincentral

(Author Instance)

EE

MultiSiteRootVirtualURIMappingMultiSiteRootVirtualUriMapping

/redirect:/.magnolia/admincentral

ui-admincentral

(Author Instance)

CE

DefaultVirtualUriMapping

/redirect:/.magnolia/admincentral

ui-admincentral

(Public Instance)

EE

MultiSiteRootVirtualURIMappingMultiSiteRootVirtualUriMapping

/redirect:/travel.html

ui-admincentral

(Public Instance)

CE

DefaultVirtualUriMapping

/redirect:/travel.html
google-sitemapCE, EE

SiteMapVirtualUriMapping


redirect:/sitemaps
rssaggregatorCE, EE

RegexpVirtualUriMapping

/rssFeeds/(.*)redirect:/rss/?feedPath=/$1
rssaggregatorCE, EE

RegexpVirtualUriMapping

/planetFeeds/(.*)


redirect:/rss/?feedPath=/$1&generatorName=planet
rssaggregatorCE, EE

RegexpVirtualUriMapping

/categoryFeeds/([a-zA-Z0-9,-]*)/(.*)

redirect:/rss/?generatorName=category&categories=$1&siteRoot=/$2
toursCE

RegexpVirtualUriMapping

/tours(.*).html

forward:/travel/tour?tour=$1
toursEE

MultiSiteRegexpVirtualURIMappingMultiSiteRegexpVirtualUriMapping


/tours(.*).html

( travel )

forward:/tour?tour=$1
toursEE

MultiSiteRegexpVirtualURIMappingMultiSiteRegexpVirtualUriMapping

/tours(.*).html

( sportstation )

forward:/tour?tour=$1