Expand my Community achievements bar.

SOLVED

Please suggest on how to cache extension less urls in cq5 dispatcher?

Avatar

Former Community Member

We have some urls in cq5 which doesn't have extensions(.html - done through vanity urls). The Apache dispatcher is not caching these pages, plz suggest on this.

Regards,

Susheel

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

It just happens, I do. I'll link to my blog post describing the approach in more detail. But, the main gist is that you use the Apache web server to "hide" the fact that AEM (technically Sling) requires an extension on every request. In Apache you 301 redirect every version of a url (ends in .html or ends in no slash) to the version that ends with a slash. Then you use a pass-through rewrite rule that adds replaces that trailing / with a ".html" as it passes the request back through the dispatcher to AEM. The pass-through rule makes this happen without the user ever knowing it, because it doesn't change the browser URL.

Note: It is important to 301 redirect requests that end in .html and no slash to the request with the slash, then again add the .html with the pass-through rule. It sounds like extra work, but it isn't. The reason is that you don't want Google to be able to index multiple URLs to the same content. You'll get penalized in terms of SEO, because Google will think you are trying to do something nasty.

Here's the full article. I hope it helps:

http://www.citytechinc.com/us/en/blog/2013/04/extensionless-urls-in-adobe-experience-manager.html

View solution in original post

9 Replies

Avatar

Level 8

Dispatcher does not cache pages that do not have an extension. I don't know of any way around this.

 

scott

Avatar

Level 2

Does someone have a working approach to solve this question?

I have the very same problem in here.

Regards

Avatar

Former Community Member

I just got know its workaround: We can have extension less urls and just add the .html extension in the apache rewrite module.

This is something needs to be checked, once I do this then I'll confirm here.

Thanks

Susheel

Avatar

Correct answer by
Former Community Member

It just happens, I do. I'll link to my blog post describing the approach in more detail. But, the main gist is that you use the Apache web server to "hide" the fact that AEM (technically Sling) requires an extension on every request. In Apache you 301 redirect every version of a url (ends in .html or ends in no slash) to the version that ends with a slash. Then you use a pass-through rewrite rule that adds replaces that trailing / with a ".html" as it passes the request back through the dispatcher to AEM. The pass-through rule makes this happen without the user ever knowing it, because it doesn't change the browser URL.

Note: It is important to 301 redirect requests that end in .html and no slash to the request with the slash, then again add the .html with the pass-through rule. It sounds like extra work, but it isn't. The reason is that you don't want Google to be able to index multiple URLs to the same content. You'll get penalized in terms of SEO, because Google will think you are trying to do something nasty.

Here's the full article. I hope it helps:

http://www.citytechinc.com/us/en/blog/2013/04/extensionless-urls-in-adobe-experience-manager.html

Avatar

Level 1

Hi Susheel,

Did you had any luck on this. We are also having the same issue and I was able to do a apache workaround on the URL, but its still not caching as the HTTP_HEADER still holds the main url (without the extension).

Thanks,

Annamalai

Avatar

Level 10

It will work. Verify the configuration for DispatcherUseProcessedURL 

Avatar

Level 1

Hi Sham,

It didn't work. This is my dispatcher configuration, still not able to see extensionless files are cached.

<IfModule disp_apache2.c>
        DispatcherConfig conf.d/dispatcher.any
        DispatcherLog    logs/dispatcher.log
        DispatcherLogLevel 3
        DispatcherNoServerHeader 0
        DispatcherDeclineRoot 1
        DispatcherUseProcessedURL 1
        DispatcherPassError 0
</IfModule>

Apache Rule:

RewriteRule    ^/(.*)$  /$1.html [PT]

Rewrite log in apache says its properly rewrite the url to include .html to the file.

Avatar

Level 2

Hi, Annamalai

I know this post it a little bit old, but I like to come back and add the solution whenever I find one ;)

I got it working with a configuration very similar to yours: DispatcherUseProcessedURL set to "1", and RewriteRule with he [PT] flag set.

But two things still needs attention:

  • My RewriteRule discards trailling slashes, because when the user access http://domain/path she is redirected to http://domain/path/ (I didn't identify who is doing this redirect, and I still didn't test it under a clean Apache setup). You may be rewriting your URL to http://domain/path/.html instead of http://domain/path.html and this may cause you problems.
  • Remember that the default dispatcher.any denies access to everything. So if your error is a "forbidden" error code, you may have to allow access to everything in dispatcher (and the deny to everything that need to be kept private).

Avatar

Level 2

Hi, Annamalai

I know this post it a little bit old, but I like to come back and add the solution whenever I find one ;)

I got it working with a configuration very similar to yours: DispatcherUseProcessedURL set to "1", and RewriteRule with he [PT] flag set.

But two things still needs attention:

  • My RewriteRule discards trailling slashes, because when the user access http://domain/path she is redirected to http://domain/path/ (I didn't identify who is doing this redirect, and I still didn't test it under a clean Apache setup). You may be rewriting your URL to http://domain/path/.html instead of http://domain/path.html and this may cause you problems.
  • Remember that the default dispatcher.any denies access to everything. So if your error is a "forbidden" error code, you may have to allow access to everything in dispatcher (and the deny to everything that need to be kept private).

I hope this helps, at least someone that may read this topic in the future.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----