Expand my Community achievements bar.

SOLVED

Allow SDI for pages with no extension

Avatar

Level 1

I have enabled SDI for my header and footer components. I have configured a dispatcher for parsing it and added 

AddOutputFilter as below. 
 

 

AddOutputFilter INCLUDES .html

 

 
 
This works well for all the .html pages and loads the header and footer well. However, there is one problem with 404 pages. For example, if I load a page with no html extension (say mydomain.com/abc/abc which is a 404 page for example) it does not load the header and footer in the page because there is no .html at the end. 
 
One solution is to simply parse every response that the dispatcher returns to check if SDI is present and it works fine if I have as below
 

 

SetOutputFilter INCLUDES

 

 
However, I want to only process html resources. Is there a way to check against response Content-Type? For example, parse only those resources that have text/html in response?
 
NOTE: I also tried 

 

AddOutputFilterByType INCLUDES text/html​

 but it does not work for some reasons.

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

We encountered a similar issue, even though we weren't using SDI. When we tried to access a URL like "/content/aem-demo/xyz.html," it correctly redirected to our custom 404 page as expected. However, when we tried to access the same URL without the ".html" extension, it unexpectedly redirected to a 403 (Forbidden) page without the header and footer.

You can find a detailed explanation of why we experienced the 403 error in the accepted answer on StackOverflow. https://stackoverflow.com/questions/48166989/why-aem-returns-403-for-requests-without-extensions 

To resolve this issue, we implemented a rewrite rule that added the ".html" extension to the URL in such cases. After applying the rewrite rule, when we accessed a URL without the ".html" extension, it now redirected to .html page and displayed the expected 404 page for a not-found page, as desired. 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ $1.html [R=301,L]

 Redirect URLs that end with a trailing slash to URLs without the trailing slash and append ".html".

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

We encountered a similar issue, even though we weren't using SDI. When we tried to access a URL like "/content/aem-demo/xyz.html," it correctly redirected to our custom 404 page as expected. However, when we tried to access the same URL without the ".html" extension, it unexpectedly redirected to a 403 (Forbidden) page without the header and footer.

You can find a detailed explanation of why we experienced the 403 error in the accepted answer on StackOverflow. https://stackoverflow.com/questions/48166989/why-aem-returns-403-for-requests-without-extensions 

To resolve this issue, we implemented a rewrite rule that added the ".html" extension to the URL in such cases. After applying the rewrite rule, when we accessed a URL without the ".html" extension, it now redirected to .html page and displayed the expected 404 page for a not-found page, as desired. 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ $1.html [R=301,L]

 Redirect URLs that end with a trailing slash to URLs without the trailing slash and append ".html".

Avatar

Level 1

Hi @Mahedi_Sabuj ,

Thanks for your response. We are using ACS AEM Commons error redirects and it is not redirecting to the URL with "/" at the end. It serves 404 pages from the same URL without changing it.

Avatar

Administrator

Not Tested but Worth Trying: 

If you are using ACS AEM Commons error redirects, you need to configure it to redirect to the URL with the .html extension. To do this, open the ACS AEM Commons error redirects configuration and add the following line:

  • redirect-to-html-extension: true

This setting will ensure that all requests to non-existent pages are redirected to the corresponding request with the .html extension. Once you have configured ACS AEM Commons error redirects, restart the dispatcher.



Kautuk Sahni