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.
Solved! Go to Solution.
Views
Replies
Total Likes
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]
I assume you're using Core Components Page component.
It looks like you're running into:
...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 @inject (but better to figure out the right injector)
private com.adobe.cq.wcm.core.components.models.Page redirectTargetPage;
@Override
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();
}
}
}
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.
Views
Replies
Total Likes
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]