2

We are using DD4T Java for one of our website build using Tridion 2013 SP1.

One of the requirements says we should not display page extensions.

Current page urls : www.mysite.com/newsroom/newsarticles/mybank.html

expected page urls : www.mysite.com/newsroom/newsarticles/mybank

How this can be done using DD4T Java?

1
  • I don't actually know how it can be done for DD4T, but we do it in the DXA (which uses DD4T underneath). Maybe someone can expand on this.
    – Nuno Linhares
    Commented Aug 3, 2015 at 11:51

5 Answers 5

2

Would this solve your issue ? - http://www.tuckey.org/urlrewrite/

2

URL Rewrite is the way to go. We did it successfully in .NET. Should be possible in Java too. A quick google gave many options "url rewrite to remove extension in java"

1
  • It is - Tuckey is a good rewriter.
    – Raimond
    Commented Mar 2, 2016 at 18:09
1

We normally put each page in a separate structure group with filename as index.html, with this you don't need to provide index.html in the URL and still the page can be accessed. Not an ideal solution though but works.

1

As Nuno mentions, DXA supports this as well. The solution is similar to the answer suggesting to change the GetContentByUrl() method.

While that solution will work, it's not ideal, as we don't want to modify core DD4T files.

I'm not sure if you use DD4T v1 or v2 for java, the below code samples are based on v2 (but a similar approach will work for v1 as well)

A better solution is to override the functionality of the DynamicPageController (https://github.com/dd4t/dd4t-2-java/blob/develop/dd4t-example-site/src/main/java/org/dd4t/springmvc/controller/DynamicPageController.java)

In line 121, you find this piece of code

Page pageModel = (Page) genericPageFactory.findPageByUrl(URL, publication);

You should alter this logic, and check for different variations of the URL variable (this variable contains the url you put in your browser.

One caveat for dd4t java version 2 is that it's better to check if a page exists by calling the method

genericPageFactory.isPagePublished(URL, publication).

Hope this helps

0

in "DD4T.providers.SDLTridion2013sp1" solution

you will find "GetContentByUrl(string Url)" append ".html" to this url string

url = url+".html";

this works for .NET, u can try the same for JAVA also.

please do let me know if this works.

4
  • 1
    Should any code in here actually be changed? You'd be changing the source for DD4T core, won't that affect your ability to upgrade later?
    – Nuno Linhares
    Commented Aug 4, 2015 at 16:39
  • this wont affect anything. after upgrade if u still need this functionality make sure u make changes to the new source code of DD4T.
    – Balajhi SV
    Commented Aug 5, 2015 at 4:57
  • Can't argue with that logic Nuno ;) Commented Aug 7, 2015 at 0:40
  • We are asking for removal of extension instead of adding please let me know your thoughts on this
    – k951
    Commented Aug 8, 2015 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.