2
votes

My problem is i want to add '.html' extension to my every blog post. For example right now i have a blog post url 'http://www.indu.com/blog/-/blogs/creating-a-custom-portlet-in-liferay' and what i want is 'http://www.indu.com/blog/-/blogs/creating-a-custom-portlet-in-liferay.html'

I would be grateful if any one can help?

1
like Advaita has pointed it out, I'm curious to know why you want to do that ? There is absolutely no impact on seo adding .html at the end of url.Jerome Cance
Jerome its our clients requirement to have .html extension in all the the pages.Milople Inc

1 Answers

3
votes

I wonder why would you want this.

Anyways, I think you can change the urlTitle field of BlogsEntry and append .html to the string. May be use a service-wrapper-hook to append .html to the urlTitle whenever a blog is created or updated.

Or you can even use a ModelListener if it exists for BlogsEntry hook to update the blog's urlTitle by using onCreate & onUpdate methods.

Edit

The urlTitle field is present in the BlogsEntry table.

You can access this in java with the following methods:

BlogsEntry blog = BlogsEntryLocalServiceUtil.getBlogsEntry(90989); // retrieves the blog-entry

String blogUrlTitle = blog.getUrlTitle(); 

blog.setUrlTitle(blogUrlTitle + ".html"); // this would set the string

You can have a check for the blogUrlTitle so that you don't have repeated .html appended to the string:

if (!blogUrlTitle.contains(".html")) { // append only if the title does not contain `.html`
    blog.setUrlTitle(blogUrlTitle + ".html");
}

You can refine your code as you like, the above is just a guide-line.

As a side-note, I would always try to reason with the client why they want something, this helps not only to fend-off bad-change-requests but also helps in giving an alternative to the client (which is less taxing on the developers like us ;-) ). In most cases this helps to understand the client's business better & provide better returns.