Hi All,
As part of beautification of URL we have removed .html from publish in page i.e. URL would be www.test.com/publish. We are using AEM inbuilt 302 redirection where it is explicitly adding .html to redirected URL.
please help if there is anyway to remove .html addition from default AEM redirect template.
Thanks in advance!!
Solved! Go to Solution.
Views
Replies
Total Likes
We can different approaches to get a polished URL
1. Create rewrite rules in web server level so that any requests resolves to full content path on to AEM publisher
RewriteRule ^/$ /content/org/test/en.html [PT]
RewriteCond %{REQUEST_URI} ^/test$
RewriteRule ^/test$ /content/org/test/en.html [PT,L]
RewriteCond %{REQUEST_URI} ^/test/$
RewriteRule ^/test/$ /content/org/test/en.html [PT,L]
RewriteCond %{REQUEST_URI} ^/test/(.+)\.html$
RewriteRule ^/test/(.*)/$ /content/org/test/en/$1.html [PT,L]
RewriteCond %{REQUEST_URI} !^/test/(.+)\.html$
RewriteCond %{REQUEST_URI} ^/test/(.+)/$
RewriteRule ^/test/(.*)/$ /content/org/test/en/$1.html [PT,L]
RewriteCond %{REQUEST_URI} !^/test/(.+)\.html$
RewriteCond %{REQUEST_URI} !^/test/(.+)/$
RewriteCond %{REQUEST_URI} ^/test/(.+)$
RewriteRule ^/test/(.*)$ /content/bt/test/en/$1.html [PT,L]
The above rules will ensure all types of request, no HTML, trailing slash, with HTML are served.
2. Create forward and reverse sling mappings
Forward
{
}
Reverse
{
}
We can different approaches to get a polished URL
1. Create rewrite rules in web server level so that any requests resolves to full content path on to AEM publisher
RewriteRule ^/$ /content/org/test/en.html [PT]
RewriteCond %{REQUEST_URI} ^/test$
RewriteRule ^/test$ /content/org/test/en.html [PT,L]
RewriteCond %{REQUEST_URI} ^/test/$
RewriteRule ^/test/$ /content/org/test/en.html [PT,L]
RewriteCond %{REQUEST_URI} ^/test/(.+)\.html$
RewriteRule ^/test/(.*)/$ /content/org/test/en/$1.html [PT,L]
RewriteCond %{REQUEST_URI} !^/test/(.+)\.html$
RewriteCond %{REQUEST_URI} ^/test/(.+)/$
RewriteRule ^/test/(.*)/$ /content/org/test/en/$1.html [PT,L]
RewriteCond %{REQUEST_URI} !^/test/(.+)\.html$
RewriteCond %{REQUEST_URI} !^/test/(.+)/$
RewriteCond %{REQUEST_URI} ^/test/(.+)$
RewriteRule ^/test/(.*)$ /content/bt/test/en/$1.html [PT,L]
The above rules will ensure all types of request, no HTML, trailing slash, with HTML are served.
2. Create forward and reverse sling mappings
Forward
{
}
Reverse
{
}
maybe another way is to sendRedirect() the response could be from the java model, this method redirects to first child:
response.sendRedirect(Util.getModifiedLink(currentPage.listChildren().next().getPath()));
getModifiedLink() test if link is internal or external and adds .html only if needed:
public static String getModifiedLink(String link) {
if (StringUtils.isNotEmpty(link) && !link.equals("#") && !(link.startsWith("/") && link.contains(".pdf")) && !link.contains("@")) {
link = link.startsWith("/") ? link + ".html" : link.contains("https://") ?
link : link.contains("http://") ? link : "http://" + link;
}
return link;
}
Views
Replies
Total Likes
Views
Likes
Replies