RedirectTarget Property Issue || .html extension issue | Community
Skip to main content
Level 5
October 29, 2020
Solved

RedirectTarget Property Issue || .html extension issue

  • October 29, 2020
  • 3 replies
  • 2697 views

Dear Team,

 

We have two pages lets say /content/A and /content/B .

 

A page redirects to Page B using page property redirect Target. so when we try to access page A, it redirects to page B, which is fine.

 

Problem: when we hit https://<domain>/content/A in browser, It redirects to   https://<domain>/content/B.html.

Is there any way to remove this html extension.

 

NOTE: we have already written webserver rules so that when we hit any page without .html extension, It works fine.

 

Thank you.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

You need to rewrite rule at webserver when you request /content/A.html it removes .html and redirect request to /content/A.

Request forwarding will not work.

 

e.g. 

RewriteRule ^/(.*).html$ /$1 [R=301,NE,L]

3 replies

Adobe Employee
October 29, 2020

I assume you're using Core Components Page component.

 

It looks like you're running into: 

 

https://github.com/adobe/aem-core-wcm-components/blob/master/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/Utils.java#L94


...based on the above code, you could add a vanity URL to the target page that is the page URLe with minus the ".html" and it looks like that should work.

 

If you wanted to write come code, you could overlay the Core Components Page's "redirect.html" script, and provide your own redirect target resolution, for example:

(This may need some syntax correction/tweaks - I wrote it in the forum post so its not exact but should give you the idea :))

 

Overlay: /apps/..../components/my-page/redirect.html

 

<template data-sly-template.redirect="${ @ redirectTarget}"> <p data-sly-use.myCustomRedirect="com.example.blah.MyCustomRedirect.class @ redirectTargetPage = redirectTarget.page"> class="cmp-page__redirect">${'This page redirects to' @ i18n} <a href="${myCustomRedirect.getURL}">${redirectTarget.page.title || myCustomRedirect.getURL}</a> </p> </template>

 

com.example.blah.impl.MyCustomRedirectImpl.java (and make corresponding SlingModel interface MyCustomRedirect.java)

@Model(adaptables = SlingHttpServletRequest.class, adapters = {MyCustomRedirect.class}) public class MyCustomRedirectImpl implements MyCustomRedirect { @RequestAttribute // I think this is right injector for the params passed in from HTL... if not, you can use the catchall @586265 (but better to figure out the right injector) private com.adobe.cq.wcm.core.components.models.Page redirectTargetPage; @9944223 public String getURL() { NavigationItem navigationItem = redirectTargetPage.getRedirectTarget(); if ( /** logic to determine if .html should be removed from redirect ** /) { return StringUtils.removeEnd(navigationItem.getUrl(), ".html")); } else { return navigationItem.getUrl(); } } }

 

arvind-1Author
Level 5
October 29, 2020

@davidjgonzalezzzz ,

 

Thank you for your reply.

 

Unfortunately,It does not work as expected.

 

Below are the two points:

 

1) Vanity url solution suggested by you still add ".html" in url in case of redirectTarget.

2) Regarding overlay of redirect.html, I think this is used for below purpose i.e. when we open page in editor  mode and page is having redirectTarget Property value. 

e.g.

Thank you once again.

Adobe Employee
October 29, 2020
ah - youre right. sorry about that - maybe that code is actually buried in the cq/Page impl. I dont see anything in the Core Components project that looks like it performs that actual redirect itself.
arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
October 29, 2020

You need to rewrite rule at webserver when you request /content/A.html it removes .html and redirect request to /content/A.

Request forwarding will not work.

 

e.g. 

RewriteRule ^/(.*).html$ /$1 [R=301,NE,L]
Arun Patidar