Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

To access a specific page directly from the publish instance without using the dispatcher

Avatar

Community Advisor

Hi All

 

We need to access a specific page directly from the publish instance without using the dispatcher, while allowing other pages to continue being served through the dispatcher.
How to do that ? can you anyone pls provide details ..

 

Thanks 

Kannan

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @KNan ,

You can achieve this in multiple ways:
     

The /rules property controls which documents are cached according to the document path. Regardless of the /rules property, Dispatcher never caches a document in the following circumstances:

  • Request URI contains a question mark (?).

    • Indicates a dynamic page, such as a search result that does not need to be cached.
  • The file extension is missing.

    • The web server needs the extension to determine the document type (the MIME-type).
  • The authentication header is set (configurable).

  • If the AEM instance responds with the following headers:

    • no-cache
    • no-store
    • must-revalidate

      If you want handle this through AEM backend then below are the 2 options.

      1. At component level component model class.

      @Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
      public class Component{

      @Inject
      private SlingHttpServletResponse response;

      @PostConstruct
      protected void init() {
      response.setHeader("Dispatcher", "no-cache");
      }
      }

       

      2. At page level, now you can call this page in body html based on some condition:

      @Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
      public class PageMOdel {

      @Inject
      private SlingHttpServletResponse response;

      @PostConstruct
      protected void init() {
      response.setHeader("Dispatcher", "no-cache");
      }
      }

       


      Thanks
      Tarun

 

View solution in original post

5 Replies

Avatar

Level 4

Hello

you can access a specific page directly from the publish instance, you can directly use the publish instance URL followed by the page's path. but generally bypassing the dispatcher isn't usually recommended for a production environment for multiple reasons like Caching and Load Balancing etc.

if you still want to access the specific page you can try the below approach 

http://<publish-server-ip>:<port>/content/project/test.html

Replace <publish-server-ip> and <port> with the IP and port number for your publish instance.

 

Thanks,

Venkat

Avatar

Community Advisor

Hi @KNan ,

To bypass a specific page from dispatcher you can do the following.
I am assuming the page to bypass is '/content/myProject/us/en/home'

APPROACH 1
1. Access your dispatcher configuration file (often named dispatcher.any).
2. Add a rule to exclude caching for the specific page. This prevents the dispatcher from intercepting requests for this page.
/excludePage
{
         /glob "/content/myProject/us/en/home"
}
/excludePage: This directive is used to define URLs that should be excluded from the dispatcher.

APPROACH 2
You can set up a rule within the /filter section to bypass the dispatcher for a particular URL.
/filter
{
    /0001
    {
        /glob "/content/myProject/us/en/home*"
        /type "deny"
     }
}


Thanks

Avatar

Correct answer by
Community Advisor

Hi @KNan ,

You can achieve this in multiple ways:
     

The /rules property controls which documents are cached according to the document path. Regardless of the /rules property, Dispatcher never caches a document in the following circumstances:

  • Request URI contains a question mark (?).

    • Indicates a dynamic page, such as a search result that does not need to be cached.
  • The file extension is missing.

    • The web server needs the extension to determine the document type (the MIME-type).
  • The authentication header is set (configurable).

  • If the AEM instance responds with the following headers:

    • no-cache
    • no-store
    • must-revalidate

      If you want handle this through AEM backend then below are the 2 options.

      1. At component level component model class.

      @Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
      public class Component{

      @Inject
      private SlingHttpServletResponse response;

      @PostConstruct
      protected void init() {
      response.setHeader("Dispatcher", "no-cache");
      }
      }

       

      2. At page level, now you can call this page in body html based on some condition:

      @Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
      public class PageMOdel {

      @Inject
      private SlingHttpServletResponse response;

      @PostConstruct
      protected void init() {
      response.setHeader("Dispatcher", "no-cache");
      }
      }

       


      Thanks
      Tarun

 

Avatar

Level 7

Hi @KNan ,

 

I think you can use ignoreUrlParams which helps to by pass the despatcher cache.

 

/ignoreUrlParams

{

  /001{ /glob "*" /type "allow"}

  /002 { /glob "specific page ID" /type "deny"}

}

 

with above rule, URL having that specific page ID always fetches the latest content from the AEM instance.

Avatar

Administrator

@KNan Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni