2 Replies Latest reply on May 23, 2013 8:59 AM by orotas

    Apache Sling JCR Resource Resolver to remove selected pattern

    MohitKBansal

      Hello,

       

      I have a requirement to remove selected pattern from all urls. Pattern will look like:

       

      <domain>/content/mysite/en/section1.html -> <domain>/section1.html

      <domain>/content/mysite/en/section1/cat1.html -> <domain>/section1/cat1.html

      <domain>/content/mysite/en/section1/cat1/page.html -> <domain>/section1/cat1/page.html

       

      I am new to mappings so looking for help from expert.

       

      Thanks for your help in advance.

       

      Regards,

      Mohit

        • 2. Re: Apache Sling JCR Resource Resolver to remove selected pattern
          orotas Level 4

          Does your domain represent a language? If there is no relationship between domain and the paths you are removing (for example www.mysite.com maps to /content/mysite/en and www.mysite.fr maps to /content/mysite/fr) then you can just use the resource resolver and not have to use /etc/maps approach. You would add /content/mysite/en/-/ to the resource.resolver.mapping property of the JCR Resource Resolver (make sure that the last property is /-/. You can do that either in the OSGI Felix console or via OSGI repository configuration.

           

          If you are using Dispatcher for caching you need to consider using Apache mod_rewrite for handling the incoming mappings. If you rely solely on the JCR Resource Resolver (or and /etc/maps approach) you can cause problems with cache flushing. If you don't use Apache mod_rewrite to change /section1.html to /content/mysite/en/section1.html then the request gets cache in the docroot as /section1.html. When you publish a change to /content/mysite/en/section1.html Dispatcher will not make the propery association and will touch the wrong stat file. Now if your stat file level is set to 0 and you set up to auto-invalidate HTML you will probably not notice the impacts immediately. If however you set your stat file level above zero, or you have non-standard auto-invalidation settings you may have problems with your cache flushing. In general anytime I do I am using Dispatcher I use Apache mod_rewrite to handle incoming rewrites. I still configure the JCR Resource Resolver to handle both incoming and outgoing rewrites so that I can test the site directly against the publish server if I need to, but I'll set up mod_rewrite to handle incoming rewrites and avoid any cache flush issues.

           

          For SEO purposes in scenarios you will want to configure Apache mod_rewrite to prevent requests directly to the full path. Often times you will either have an outgoing link not get rewritten to the short URL, or someone will send out the full link by accident so you will want to prevent those links from working - potential by doing a 301 redirect of /content/mysite/en/section1.html back to /section1.html. This prevents SEO issues, but you do have to make sure you don't create an infinte loop since the redirected request will then get rewritten to the long URL.