No Dutch
Startpagina » Blog » How to remove /web/guest from Liferay URL’s Share/Bookmark

How to remove /web/guest from Liferay URL’s

Op 19 mei 2010 door Kristof Verbraeken in categorie Liferay

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:

layout.friendly.url.private.group.servlet.mapping=/group
layout.friendly.url.private.user.servlet.mapping=/user
layout.friendly.url.public.servlet.mapping=/web

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.

In short:

  1. The layout.friendly.url.private.group.servlet.mapping property (/group by default) is mapped to the private pages of a community.
  2. The layout.friendly.url.public.servlet.mapping property (/web by default) is mapped to the public pages of a community.
  3. The layout.friendly.url.user.servlet.mapping property (/user by 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.

  1. 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 e-kon.dev.

    Liferay Portal Instances

  2. Have a closer look at the frontend. When you browse to the newly added instance you’ll see that the /web/guest is present in the URL’s.

    Liferay Frontend Before

  3. Configure the Virtual Hosting.

    Log in (as an Administrator) and go to the Communities overview.

    Liferay Manage Pages

    Choose Manage pages in the overview:

    Liferay Manage Pages

    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.

    Liferay Virtual Host

  4. Check the frontend again and browse  to www.e-kon.dev. You’ll notice that /web/guest is no longer present in URL’s! Note that you can still access pages with the /web/guest prefix!

    Liferay Frontend After

All done!

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?



Reacties

Gaurav Talwar ()

Hi there,

Nice tutorial.. But as you said the page can still be accessed with /web/guest prefix. I think this is still bad for SEO as duplicate content is getting served from different url's. What do you think abou this

Thanks
Gaurav

Sivan Hermon ()

Hi there,

I was really happy to see I'm not the only one fighting this.
I'm trying to change the settings so each user will see his community page after his login.
I followed this tutorial (with and without creating the new portal instance), but it did not work for my :(
My portal-ext.properties is basically empty.

Any idea or suggestions?

Kristof Verbraeken ()

Hello,

Sorry for my late response.

@Guarav

You’re right about what you’re saying about duplicate content, but search engines are not working “trial and error”.

By this I mean that search engines will not find the content on the “bad” URL’s if you don’t link to those “bad” URL’s but always use the “good” URL’s.

There are many other frameworks (e.g. Zend or CodeIgniter) where you can also configure search engine friendly URL’s, but the same content will still be available on the “bad” URL’s.

This isn’t such a terrible thing to do if you always link with the good URL’s.

To be completely sure in Liferay, you could also prevent search engine from indexing URL’s that start with “/web/guest” using a robots.txt file:

User-agent: *
Disallow: /web/guest/*

I hope this comment was useful!

@Sivan

Can you provide more information about your Liferay configuration?

Kind regards,
Kristof

Sivan ()

I ended up finding a solution to what I wanted in another way.
Check this out:
http://www.liferay.com/community/forums/-/message_boards/message/5932208

santosh ()

I tried it with liferay 6.0 SP1 and it does not work.

Trend ()

hi
and if I want my server to attack from both www.exampl.com URL / exampl.com

thks

Reactie plaatsen

( Je email is veilig bij ons! )