From the moment you give Liferay a try and start your portal for the very first time you’ll notice something a bit dirty about Liferay URL’s.
That’s right: I’m talking about the
/web/guest prefix in the frontend. In the early days I was working with Liferay, I just thought that it was some “Java web development hocus pocus thing” that you will just have to accept when doing a Liferay implementation.
Keeping the prefix in your URL’s is certainly not a disaster, but for SEO matters clean URL’s are prefered.
It’s always a good idea to check the Liferay
portal.properties first for properties that might be interesting for your Liferay implementation. You’ll find some properties in portal.properties that seem interesting regarding URL’s in Liferay.
Check out these properties:
Looks great doesn’t it? It looks like we can get rid of the
/web/guest very easily! Just fill in an empty string for the
layout.friendly.url.public.servlet.mapping property and we should be all done, right? I warn you though: don’t do this! Because you will break your Liferay installation completely and you won't be able to reach your portal anymore.
This is not the way to remove the
/web/guest from Liferay URL’s. The right answer: take a closer look at Virtual Hosting in Liferay. There’s already an article on the Liferay Wiki about this topic.
/groupby default) is mapped to the private pages of a community.
/webby default) is mapped to the public pages of a community.
/userby default) is mapped to the user pages.
What we’re going to do through Virtual Hosting is mapping one domain directly to the public pages of a community. When this mapping exists Liferay no longer needs the
/web/guest prefix (and other mappings listed above) to know which community a visitor is accessing (with the “/web/guest” prefix you are accessing the public pages of the Guest community).
In the steps below I will show you how to remove the
/web/guest from the frontend of a Liferay portal.
Add a new Liferay instance (only if needed). You must be logged in (as omniadmin) to do this. In this example I’m adding a new instance for the domain
Have a closer look at the frontend. When you browse to the newly added instance you’ll see that the
/web/guestis present in the URL’s.
Configure the Virtual Hosting.
Log in (as an Administrator) and go to the Communities overview.
Choose Manage pages in the overview:
Choose Settings in the tabs.
For the Public Virtual Host (this will be mapped to the Public Pages) enter
www.e-kon.dev. You can leave the Private Virtual Host just empty.
Check the frontend again and browse to
www.e-kon.dev. You’ll notice that
/web/guestis no longer present in URL’s! Note that you can still access pages with the
I hope this article was useful to all Liferay developers out there. Feel free to comment or ask questions about the Virtual Hosting feature in Liferay through our comment section. Do you know other ways to handle this?