Friday, May 31, 2013

How to configure custom mappings based on run mode?


Scenario: Having a requirement where we need to configure sling mappings based on run mode.

Example: Assume that we’ve three different environments called ‘author’, ‘preprod’ and ‘prod’

When we access http://<hostname>:<port>/projects   It has to redirect to three different urls based on run modes.

In author instance it should be redirected to  /content/test/author.html

In preprod instance it should be redirected to /content/test/preprod.html

In prod instance it should be redirected to /content/test/prod.html


1.  Create different config.<runmode> nodes (of type sling:Folder) inside /apps/system/

Eg:     type    Sling:Folder

config.preprod    type    Sling:Folder         type     Sling:Folder

2.   Create a new node of type Sling:OsgiConfig inside configuration folders.

       node name:

       type:            Sling:OsgiConfig

      2.a:    Add following properties to the node:

          1.  property name:

     type:    String

              value:    /etc/map.<runmode>

2. property name: resource.resolver.manglenamespaces

    type: Boolean

    value: true

3. property name: resource.resolver.default.vanity.redirect.status

    type: Decimal

    value: 302

4. property name:  resource.resolver.mapping

   type: String []

   value: /-/

5. property name:  resource.resolver.searchpath

   type: String []

   value: "/apps","/libs","/apps/foundation/components/primary","/libs/foundation/components/primary"

6. property name: resource.resolver.required.providers

   type: String[]


7. property name: resource.resolver.allowDirect

   type: Boolean

   value: true

8. property name: resource.resolver.virtual

   type: String[]

   value: /:/

3.    Create different map configurations inside /etc.

       In our example, we can create Sling:Folders with following names:


       b.   map.preprod


4.    Create configuration node for sling mapping inside /etc/map.<runmode>

     Eg:      Node name:     test

                 type:     Sling:OsgiConfig

       4.1  Add following properties to the config node

              a.   property name:    sling:match

                    type:    String

                   value:    <Some regular expression/match>

b.    property name: sling:redirect

      type: String

                value: <Some regular expression/match>

5.   Test it..

1 comment:

  1. Is there way to hide /jcr:content/renditions from the url, below is an example


    Expected result:

    any inputs or help in finding the solution will be higly appreciated