Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

What am I missing for this URL rewriting scenario?

LinearGradient
Level 7
Level 7

I basically want short URLs to get resolved and HTML pages to be generated with short URLs for a CQ5 website. So far short URLs are getting mapped to long URLs as expected, but links in the generated HTML pages are not getting shortened. For example, I am expecting this link:

    <script type="text/javascript" src="/content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae/style/clientlibs.1395978029951.js"></script>

To be shortened to:

    <script type="text/javascript" src="/style/clientlibs.1395978029951.js"></script>

But it is not and remains intact.

The website is stored under /content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae/ and it is accessible from http://site-1:4503 in my local development environment.

I have defined the following URL mappings (by following this article: http://www.cognifide.com/blogs/cq/multidomain-cq-mappings-and-apache-configuration/)

{
   "jcr:primaryType":"sling:Folder",
   "http":{
      "jcr:primaryType":"sling:Folder",
      "site-1.4503":{
         "sling:internalRedirect":[
            "/content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae"
         ],
         "jcr:primaryType":"sling:Mapping",
         "redirect":{
            "sling:internalRedirect":[
               "/content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae/$1",
               "/$1"
            ],
            "jcr:primaryType":"sling:Mapping",
            "sling:match":"(.+)$"
         }
      },
      "site_1.4503":{
         "sling:internalRedirect":[
            "/content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae/home.html"
         ],
         "jcr:primaryType":"sling:Mapping",
         "sling:match":"site-1.4503/$"
      }
   }
}

When I test this mapping in http://localhost:4503/system/console/jcrresolver, it seems to be working as expected. For example,

    /content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae/style/clientlibs.1395978029951.js

is mapped to

    http://site-1:4503/style/clientlibs.1395978029951.js

and

    http://site-1:4503/style/clientlibs.1395978029951.js

is resolved to:

    JcrNodeResource, 
    type=cq:ClientLibraryFolder,
    superType=null, 
    path=/content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae/style/clientlibs

Also when I go to http://site-1:4503/style/clientlibs.1395978029951.js in my browser, the JS file is rendered as expected.

However when I open the HTML, as mentioned earlier, none of the long URLs are rewritten to their shorter forms.

What am I missing here?

3 Replies
Amit_Kumar
Community Advisor
Community Advisor

LinearGradient wrote...

I basically want short URLs to get resolved and HTML pages to be generated with short URLs for a CQ5 website. So far short URLs are getting mapped to long URLs as expected, but links in the generated HTML pages are not getting shortened. For example, I am expecting this link:

    <script type="text/javascript" src="/content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae/style/clientlibs.1395978029951.js"></script>

To be shortened to:

    <script type="text/javascript" src="/style/clientlibs.1395978029951.js"></script>

But it is not and remains intact.

The website is stored under /content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae/ and it is accessible from http://site-1:4503 in my local development environment.

I have defined the following URL mappings (by following this article: http://www.cognifide.com/blogs/cq/multidomain-cq-mappings-and-apache-configuration/)

{
   "jcr:primaryType":"sling:Folder",
   "http":{
      "jcr:primaryType":"sling:Folder",
      "site-1.4503":{
         "sling:internalRedirect":[
            "/content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae"
         ],
         "jcr:primaryType":"sling:Mapping",
         "redirect":{
            "sling:internalRedirect":[
               "/content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae/$1",
               "/$1"
            ],
            "jcr:primaryType":"sling:Mapping",
            "sling:match":"(.+)$"
         }
      },
      "site_1.4503":{
         "sling:internalRedirect":[
            "/content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae/home.html"
         ],
         "jcr:primaryType":"sling:Mapping",
         "sling:match":"site-1.4503/$"
      }
   }
}

When I test this mapping in http://localhost:4503/system/console/jcrresolver, it seems to be working as expected. For example,

    /content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae/style/clientlibs.1395978029951.js

is mapped to

    http://site-1:4503/style/clientlibs.1395978029951.js

and

    http://site-1:4503/style/clientlibs.1395978029951.js

is resolved to:

    JcrNodeResource, 
    type=cq:ClientLibraryFolder,
    superType=null, 
    path=/content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae/style/clientlibs

Also when I go to http://site-1:4503/style/clientlibs.1395978029951.js in my browser, the JS file is rendered as expected.

However when I open the HTML, as mentioned earlier, none of the long URLs are rewritten to their shorter forms.

What am I missing here?

 

Step1: Go to System configuration i.e.  /system/console/configMgr>> Apache Sling Resource Resolver Factory

Step 2: Add a new URL mapping /content/foo/c0/06/9d/3d93a858-efb4-4619-8f9e-5edc65d0f5ae/-/

Regards,

Amit

Amit_Kumar
Community Advisor
Community Advisor

Don't forget to select the correct Mapping Location in your configurations.

kautuk_sahni
Employee
Employee

Hi

Adding to what Amit has said, you can achieve this by Root Mapping, Page Redirects, sling:Mapping Redirects, Dynamic Redirects and Deep Linking.

Please have a look at this community article for more help:

Link:- http://aem.matelli.org/url-mapping-and-deep-linking/

Page Redirects: Sometimes pages are meant to simply be ways of grouping subpages, and not locations that a user should land on directly. These kind of pages can be set up as redirect component. A good example is the /content/geometrixx sample page.page_redirectTo recreate this page redirect, either set it up when creating the page in AEM’s site builder (under New Page -> Advanced -> Redirect), or just change the properties of that page in CRX: expand the content/{page} node Click the ./jcr:content node Change the sling:resourceType property to be foundation/components/redirect Add a new String property called redirectTarget Give redirectTarget a value of the new page (e.g. /content/myproject/mypage/mysubpage) Tip 1: If a site is being built in one language, there’s no need to mimic the /en/ structure shown in the geometrixx example. Tip 2: The sling extension (e.g. .html) will automatically carry over to the redirect page, and shouldn’t be specified sling:Mapping Redirects: AEM’s most powerful URL-manipulation feature, a set of redirect components, is often overlooked because application servers don’t traditionally have this ability. But CQ’s built in Vanity URL support, namespace mangling, and internal tools all make use of this ability. A custom application can too, for instance, by remapping all /content project to /content/myproject In CRX, navigate to the /etc/map node. Open (or create) the http node of type sling:Folder Create a node called content of type sling:Mapping Add a property called sling:match and give it a value of localhost.4502/content/ Add a property called sling:internalRedirect and give it a value of /content/myproject Now navigate to http://localhost:4502/content/mypage.html. The browser will display the URL that was entered, but internally AEM will be referencing the mapped directory structure. Another way to test how CQ is handling mapping is by opening the Sling Resource Resolver tool. Log in with normal admin credentials (the default being admin/admin), enter http://localhost:4502/content/mypage.html into the test box, click Resolve and examine the “path” property that is output below the test box. Problem: Remappping all of /content will also remap /content/dam, breaking current links Solution: Override that particular mapping to point to itself Within CRX, navigate to the /etc/map/http node. Create a node called content_dam of type sling:Mapping Add a property called sling:match and give it a value of localhost.4502/content/dam/ Add a property called sling:internalRedirect and give it a value of /content/dam/ This node will point to itself, and override the above /content/ mapping. The mapping rule resolution I believe is determined by string length and can be manipulated with sling:OrderedFolder. If readers have experience with this, please add comments below. It hasn’t been necessary to experiment with this feature for my projects. The above problem will be more apparent if, instead of /content/ being mapping to the content directory, the root directory is also mapped. Tip: Do not remap the root directory using this technique. There is a better technique above While I recommend against remapping the root directory on author instances, as it will break things like authentication and CRX, it can still be done. In which case, the following directories also need to be remapped to point to themselves: \apps\ \content\dam\ \etc\ \home\ \libs\ \tmp\ \var\ This should allow most applications and features of AEM to still work. But some monitoring of the app should take place to make sure other locations are not inappropriately being remapped. Tip: If there’s a question about which URLs are being accessed by browsers or CRX, a tool like Fiddler can monitor and report on it. Dynamic Redirects: Thankfully, both the sling:match and sling:internalRedirect nodes use regular expressions, so that URL mapping can be more dynamic. So things like top-level links can be remapped to strip off the “.html” extension. Within /etc/map/http Create a new node named posts of type sling:Mapping Add a property called sling:match with value localhost.4502/posts/([^/]+)$ Add a property called sling:internalRedirect with value /content/myproject/posts/$1.html This will allow posts to be accessed without an extension. There are other ways of performing this particular task, such as adding a GET.jsp entry to the components, but mapping redirects are the best way to not interfere with the rest of the Sling resolution logic.

 

I hope this would help you.

Thanks and Regards

Kautuk Sahni