how sling rewriter works clarification

北城余情 提交于 2019-12-05 19:46:05

I have used these mapping on CQ 5.6.1 and they seem to work. Please find JSON exported from my instance:

{
  "jcr:primaryType": "sling:OrderedFolder",
  "home": {
    "sling:internalRedirect": "/content/geometrixx/en.html",
    "sling:match": "localhost.4503/$",
    "jcr:primaryType": "sling:Mapping",
  },
  "localhost.4503": {
    "sling:internalRedirect": "/content/geometrixx/en",
    "jcr:primaryType": "sling:Mapping",
    "redirect": {
      "sling:internalRedirect": [
        "/content/geometrixx/en/$1",
        "/$1"
      ],
      "sling:match": "(.+)$",
      "jcr:primaryType": "sling:Mapping",
    }
  }
}

The only change I've made is the port separator in the first sling:match column - I have changed it form colon to a dot. Just to be sure we're working on the same configuration, I've created a CQ package containing my config.

This configuration makes 3 things:

  1. When user requests http://localhost:4503/ they will be redirected to /content/geometrixx/en.html
  2. When user requests http://localhost:4503/products.html (or any other page from the /content/geometrixx/en subtree) they will be redirected to /content/geometrixx/en/products.html.
  3. All paths in <a>, <img> and <form> tags will be mapped to their short version, eg.:

<a href="/content/geometrixx/en/products.html">Products</a>

will be rewritten to

<a href="/products.html">Products</a>


About your second question - Sling mappings doesn't allow to redirect user to the mapped version of the URL. Geometrixx site uses BrowserMap library, which (amongst other things) redirect user to the shortened version of the URL using JavaScript. That's why entering following URL:

http://locahost:4503/content/geometrixx/en/products.html

will redirect you to to /products.html a second after the page is loaded.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!