« Back to Custom Post-login...

Customizing the default page after login

How do I specify which page a newly logged in user gets redirected to?

How do I redirect my users to the page they were just looking at.. after they login? #

All you need to do is set the following value in your portal-ext.properties file:


Also make sure that there is no landing page defined. Remove lines with


How do I redirect my users to a specific page (or community).. after they login? #

4.3.x and on #

If your "redirect rule" is very simple.. such as "after login, redirect all users to page '/web/guest/home'", then you just need to add 2 values to your properties file:


If you want to include more complex logic, you will need to modify the DefaultLandingPageAction.java file

DefaultLandingPageAction.java #

In portal.properties, notice the property login.events.post, after LoginPostAction is called, DefaultLandingPageAction is also called.


This class "DefaultLandingPageAction.java" has been created for you here:


Liferay is setup to read two properties, AUTH_FORWARD_BY_LAST_PATH and DEFAULT_LANDING_PAGE_PATH. To do more complex redirect logic, we are basically setting a property to tell Liferay to send the newly logged in user to the page specified in path, the page he was just looking at. BUT.. before we do this, we override the value of path. Now we have complete control over where to send the user.

For more complex redirect logic we just need to pull the necessary values to get our desired path, then override the path variable.

You can look at this code snippet to help get you started on how to pull the desired information:

		ThemeDisplay themeDisplay =

		User user = themeDisplay.getUser();

		long userId = themeDisplay.getUserId();

		List userGroups = UserGroupLocalServiceUtil.getUserUserGroups(userId);

Finally, override this path variable

		String path = PropsUtil.get(PropsUtil.DEFAULT_LANDING_PAGE_PATH);

4.2.x and before #

take a look at the bottom of the LoginPostAction.java file. at the bottom of the run method is some code that has been commented out:


         // To manually set a path for the user to forward to, edit
         // portal.properties and set auth.forward.by.last.path to true.

         /*Map params = new HashMap();

         params.put("p_l_id", new String[] {"PRI.3.1"});

         LastPath lastPath = new LastPath("/c", "/portal/layout", params);

         ses.setAttribute(WebKeys.LAST_PATH, lastPath);*/

If you switch the "auth.forward.by.last.path" variable to "true", then after you login, it will redirect you to the url you were just at before you logged in.. which is stored in the variable "lastPath".

Soo.. lets say that you wanted to redirect certain users to certain pages. If you changed that "lastPath" value.. you now control what page the newly logged in user would get redirected to. You could get the logged in user info via:


and then query the database based on that userid to get other info.

On a side note, if you were to do this quickly, you can just uncomment the code and add your own logic to set the lastPath variable at the end of the LoginPostAction method, but a cleaner way would be to put these modifications elsewhere.

1. create a new class, and in the run() method, put in your code. This class will have the same structure as LoginPostAction, except that it only contains the new code (the code that was commented out).

2. Then change the value in "portal.properties" by editting your "portal-ext.properties" file so that it will also hit your newly created class.

3. Add your own class to the "login.events.post" line so that it looks something like:

0 Attachments
Average (1 Vote)
The average rating is 2.0 stars out of 5.
Threaded Replies Author Date
Test for... Arcko Duan July 22, 2008 7:39 PM
I'm on 5.1.1 and this: ... Bob Evans September 27, 2008 1:12 PM
For me it works fine. You have to set the... Paul Voors September 30, 2008 3:36 AM
How do you set the friendly url? I am having... Michael Poznecki January 29, 2009 7:05 AM
Hi Michael, I'm looking for the same... please... suresh reddy k January 29, 2009 1:32 PM
hi, go to manage pages select the page for... Sachin Pathare April 23, 2009 5:58 AM
Michael, From the 'Communities' admin portlet... Jason Reast-Jones February 2, 2009 7:50 AM
Its working fine.. Thanks Ravi Kumar Gupta July 1, 2009 3:17 AM
We have implemented a CustomLandingPageAction... Edgar Vonk September 24, 2009 6:17 AM
Did you solve this issue? I have a similar... Andreas Thiel November 5, 2009 7:04 AM
I worked a bit on it. I injected my own... Andreas Thiel November 6, 2009 3:34 AM
Interesting! No, I never found a solution for... Edgar Vonk November 18, 2009 4:23 AM
Two gotchas I found when implementing my own... Peter Connolly September 25, 2009 11:52 AM
I have now been trying to make my own... Armaz Mellati January 9, 2011 4:02 AM
Now I got it working. It was kind of my own... Armaz Mellati January 9, 2011 12:29 PM
I have the same problem,I need to get the user... mohamed bouker April 28, 2011 9:53 AM
I m doing the same thing using hook ,but... Nitesh Kr Sahay January 10, 2012 4:13 AM

Test for http://support.liferay.com/browse/LEP-6816
Posted on 7/22/08 7:39 PM.
I'm on 5.1.1 and this:


is simply not working.

I set default.landing.page.path=/web/10601/home

and it ALWAYS goes to /group/10601/1.

This is holding up our release to production. HELP PLEASE.
Posted on 9/27/08 1:12 PM.
For me it works fine.
You have to set the friendly url for the home page /home where your refer to in: "/web/10601/home".
(you can set an friendly url for "10601" to!)
Posted on 9/30/08 3:36 AM in reply to Bob Evans.
How do you set the friendly url? I am having the same problem that Bob did.
Posted on 1/29/09 7:05 AM in reply to Paul Voors.
Hi Michael,

I'm looking for the same... please let me know if you get pointers!!!

Posted on 1/29/09 1:32 PM in reply to Michael Poznecki.

From the 'Communities' admin portlet either search for your community or click 'All Communities'. On the action menu for the community in question go to 'Manage Pages' Then click the 'Settings' tab, then 'Virtual Host', it's a bit misleading, but that's where you set the Friendly URL.

Posted on 2/2/09 7:50 AM in reply to Michael Poznecki.
go to manage pages select the page for which u want, there is a option for friendly URL, change it accordingly

Posted on 4/23/09 5:58 AM in reply to suresh reddy k.
Its working fine..

Posted on 7/1/09 3:17 AM.
We have implemented a CustomLandingPageAction using the description above and this works just fine. We have separate landing pages depending on the role of the user.

However I would also like to be able to redirect users to their landing page whenever they go the root URL of our portal ('/'). The functionality we have now is:
# user logs in
# Liferay redirects user to correct landing page (using our CustomLandingPageAction). e.g.: http://localhost:8080/group/test/home
# user manually changes the URL or follows a bookmark to: http://localhost:8080
# Liferay redirects the user to the _default_ landing page: http://localhost:8080/web/guest (or whatever URL is configured using the default.landing.page.path)

Is there an event or filter somewhere in Liferay that we can use to send users to their landing page when they go to the root URL?
Posted on 9/24/09 6:17 AM.
Two gotchas I found when implementing my own landing page forward logic:

1. The code for getting the user info returns null on the line:
ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);

I had to get the user information this way instead:

String userIdString = request.getUserPrincipal().getName();
long userId = new Long(userIdString);
User user = UserLocalServiceUtil.getUser(userId);

2. The instructions don't talk about how to deploy the modified DefaultLandingPageAction. You could open portal-impl.jar and replace DefaultLandingPageAction.class. I'm not a big fan of modifying vendor jars. I would recommend opening portal-ext.properties and adding a line like this:


Create a class named MyLandingPageAction (you can look at the source for DefaultLandingPageAction for a sample) and modify accordingly. Jar it up by itself and then drop the jar in tomcat-6.0.18\webapps\ROOT\WEB-INF\lib
Posted on 9/25/09 11:52 AM.
Did you solve this issue? I have a similar demand: The company logo, normally placed in the top left, refers to ThemeDisplay.getURLHome(), which is _not_ the page my custom landing page dispatcher selects on login. How to achieve this?

Currently, I'm thinking about patching init.vm in the theme - this is where $company_url is set -; or to overwrite ThemeDisplay.setURLHome() - I have no clue what side effects this could cause.

Posted on 11/5/09 7:04 AM in reply to Edgar Vonk.
I worked a bit on it.

I injected my own PortalUtil class, replacing PortalImpl, by adding the following lines to ext-spring.xml:

<bean id="com.liferay.portal.util.PortalUtil" class="com.liferay.portal.util.PortalUtil">
<property name="portal">
<bean class="com.vodafone.portal.liferay.MyPortalImpl" />

MyPortalImpl inherits from PortalImpl and overrides the getHomeURL() method:

public class MyPortalImpl extends PortalImpl

public String getHomeURL(HttpServletRequest request) throws PortalException, SystemException
String portalURL = getPortalURL(request);
Company company = getCompany(request);
String homeURL = company.getHomeURL();
if (Validator.isNull(homeURL))

// added
HttpSession session = request.getSession(false);
if (session != null)
LastPath lp = (LastPath) session.getAttribute("LANDING_PAGE");
if (lp != null)
String specificHomeURL = lp.getPath();
if (Validator.isNotNull(specificHomeURL))
homeURL = specificHomeURL;
// end

return portalURL + getPathContext() + homeURL;

Works like a charm - unitl now ;-)

Could someone validate this approach? Is it feasible? Any sideeffects I did not encounter yet? Would it make sense to extend the "home URL" concept/strategy of Liferay in this regard (user specific home page takes precedence over company home page, takes precedence over default company home page)?
Posted on 11/6/09 3:34 AM in reply to Andreas Thiel.
Interesting! No, I never found a solution for our problem. Quite bizarre because it seems to me almost everybody would have this issue.

Anyway, your solution sounds pretty good. How did you package this stuff? Where is the ext-spring.xml you are talking about?
Posted on 11/18/09 4:23 AM in reply to Andreas Thiel.
I have now been trying to make my own DefaultLandingPageAction to work for several hours, but it just doesn't matter what I set the path to. No matter the value of the path set to the session by this code, it has no effect. I still get redirected to the 'guest' community.

LastPath lastPath = new LastPath(
new HashMap<String, String[]>());
HttpSession session = request.getSession();
session.setAttribute(WebKeys.LAST_PATH, lastPath);

I am starting to think I am facing a bug in 6.0.5.

Has anybody got this working on 6.0.5 ?

Armaz (in very bad mood)
Posted on 1/9/11 4:02 AM.
Now I got it working. It was kind of my own fault.
I missed this one :
I had it set to false.

Now that I got here, I can summarize my experience :
- first I had a lot of problems making it work as an ext-plugin. I just had to give up, since the classloader just ignored my class and used the original one. I had to do it as Peter suggested. I made my own class and put it beside the original one in the source-code of the LR-portal. So I made a jar of the resulting Class file and put it in the lib directory under ROOT.

- So I got to the other problem that everyone else have pointed out, there is no WebKeys.THEME_DISPLAY in the session emoticon. Very irritating since I planed to use it in a call like this
group.getPathFriendlyURL(privateLayout, themeDisplay)
My workaround is hardcoding that part of the path ("/group").

- My last problem was the one I started this post with.

Good luck to other who are to walk this path.

Posted on 1/9/11 12:29 PM in reply to Armaz Mellati.
I have the same problem,I need to get the user 's custum attribute by doing :
User us=PortalUtil.getUser(request);
String default =us.getExpandoBridge().getAttribute("nameofattr");
string path="/web/"+default;
but i can't get the expandobridge from session can you help me
Posted on 4/28/11 9:53 AM in reply to Armaz Mellati.
I m doing the same thing using hook ,but classloader ignored my classes...
what can i do for this?........
Posted on 1/10/12 4:13 AM in reply to mohamed bouker.