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/Relative
    fromUri: /winter2016
    toUri: forward:/marketing/campaigns/winter2016
  • Absolute

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

...

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

...

  • 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.module.googlesitemap.config.mapping.*
    • Javadoc resource link
      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.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 mapping will only match the request if both the specified regular expression and the specified site match.

  You 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
Anchor
deprecated-classes
deprecated-classes

...

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

Regular expression

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

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
class
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-9a-9AzA-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

Node name

Value

Mgnl f
virtualUriMappings


Mgnl n
siteMaps


Mgnl p
class

info.magnolia.module.googlesitemap.config.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.

...

Mgnl p
prefix

...


Mappings in the default installations of Magnolia

/ActivationHandler
ModuleEdition

Mapping class

From

(Site)

ToactivationCE, EE

DefaultVirtualUriMapping

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

forward:/.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