« Voltar para FrontPage

Changing context path of portal

This article describes the issues related to migration of your Liferay portal to another context path. What context path means? In one sentence, the context path is the name after slash, by which your application is accessible. If your server is running under mydomain.com/ and you want to make it accessible under mydomain.com/portal, this article is definitelly for you!. If you ever have been developing some web application, then the term context path should be well-known for you. Anyways, let's start with a short description. If you are familiar with this term, just skip the first chapter.

Well, usually if you deploy your portal to your Application Server, or Servlet Container as Apache Tomcat, your Liferay portal runs under ROOT Context path, meaning it is available under <your_ip_address>:<your_server_port>/, i.e : 127.0.0.1:8080/ .The "/" at the end is exactly signalizing, that your application is running under root context path, thus is accessible under  "/". So now we now, that the "magic slash" is signalizing the context path of our application. Logically, if our application is accessible under /application, then the context path of our application is "application".

One important thing to notice is, that Liferay OOTB uses some friendly URL's to identify all webs in portal. So your portal URL does not look like 127.0.0.1:8080/, but maybe like 127.0.0.1:8080/web/guest , or 127.0.0.1:8080/group/user . This is because Liferay uses the keyword web to access public pages of a group (organization, community or user) and the keyword group to access private pages of mentioned groups. These keywords are of course configurable, so you can select your own keywords, which will be used to access your private and public pages.. It's important to not mix these terms with term of context path.

So now we know, what the context path is, we also know, which URL's are used to identify private and public pages in Liferay portal. So let's go straight to something more complicated. As I previously mentioned, Liferay Portal is by default using the root context path, thus accessible directly under mydomain.com/.  Let's take an example, when you want your Liferay portal to be accessible under mydomain.com/portal. As a matter of fact, you can accomplish this in different ways, i.e by configuration on HTTP server, or some redirection, but we will explain here, how this can be achieved on the level of Liferay portal.

Before we start, make sure that your Application server is stopped.

First of all, let's take a look at your current installation of Liferay portal. Let's assume, you are using Apache Tomcat as your servlet container. So let's look at your folder <installation-path-of-your-apache-tomcat>/webapps. In this folder you should see at least 1 folder called ROOT. This is the current installation of your Liferay portal, accessible under context path /.

Once you have this folder, you can rename to a new name signalizing your context path. So if you want your portal to be accessible under /portal, let's rename ROOT to portal. This renaming causes your portal to be accessible under a new context path.

Anyways, because there are some internal processes in Liferay Portal using the context path as well, we need to set a special property in Liferay portal. For this purpose let's find (or create a new if it does not exist yet) the file portal-ext.properties. This should be located under <installation-path-of-your-apache-tomcat>/webapps/<your-renamed-liferay-folder>/WEB-INF/classes. As mentioned before, if this file does not exist by you, create a new one.

In this file, add the following line:

portal.ctx=/<your-new-context-path>

Instead of  <your-context-path> you should write the new context path. So if your renamed your ROOT folder previously to portal, then you should write the following line here:

portal.ctx=/portal

Lastly, you'll need to navigate to <installation-path-of-your-apache-tomcat>/conf/Catalina/localhost. There will be a file called ROOT.xml, just rename it to match your context path, in our case portal.xml.

So, that's it. Your portal was now migrated to a new context path and you can start the application server. After starting, it should be accessible under your new selected context path, so in this example under /portal.

Well, that's it. The thing is, that even if you migrated your portal succesfully using previous steps, there are some issues, that need to be solved. Once you had in your portal some Web content articles previously refferencing to your documents, internal pages or images, all these will be broken. This is because Liferay is storing all refferences to these resources in a form of static text, thus not changing the links after change of context path. But no panic, we have a solution for this. I have developed a portlet plugin, which is after deployment accessible in control panel and allows you to migrate all your articles to new context path in all your organizations/communitites. This plugin is a port of community plugins and accessible here : http://www.liferay.com/downloads/liferay-portal/community-plugins/-/software_catalog/products/8246761

So have fun and let me know, if you have some problems/questions issues either with migration or using this plugin!

Jan.

0 Anexos
34082 Visualizações
Média (2 Votos)
A média da avaliação é 4.5 estrelas de 5.
Comentários
Respostas do tópico Autor Data
Hi, Our client requirement is to have two... Balaji Murugesan 3 de Agosto de 2011 00:08
Hi Balaji, I think this should be no problem.... Jan Gregor 5 de Agosto de 2011 05:28
Hi, after trying to change the context path... Inge Klein 1 de Setembro de 2011 05:10
Nice Article Jan !!! Jignesh Vachhani 29 de Setembro de 2011 03:08
This smells like a hack, meaning changing files... Alex Leshinsky 30 de Novembro de 2011 18:15
How to get this context path inside custom... Manoj Satyagi 18 de Abril de 2012 21:11
virtual path can be used Gowtham Mani 7 de Maio de 2012 05:18
I have tried to localize the plugin but I can't... Rafael Lluis 28 de Janeiro de 2013 02:54
Hi Rafael, were you able to get the portlet... Rohit Gupta 25 de Fevereiro de 2014 12:08
You can find it on the marketplace: ... Rafael Lluis 25 de Fevereiro de 2014 12:19
i am looking for the portlet-plugin referred in... Rohit Gupta 25 de Fevereiro de 2014 12:06

Hi,
Our client requirement is to have two instances of portal. So can we have different Context path for the new instance that we create in LR portal.

Eg: 1st instance - www.example1.com
2nd instance - www.example2.com/portal

If its not possible, how can we achieve the requirement.

Thanks,
Bala
Postado em 03/08/11 00:08.
Hi Balaji,

I think this should be no problem. Take a look at virtual hosts section at liferay admin guide.

Regards,
Jan.
Postado em 05/08/11 05:28 em resposta a Balaji Murugesan.
Hi,
after trying to change the context path from "/" to "/public" and after migrating my organization CDX by help of the migration tool, the my CDX pages are not displayed properly anymore. The links are updated, but the page looks broken, it seems, that the stylesheet information can not be found anymore (no colours etc.). The organization CDX uses the jedi theme and a 3 column layout. Are there any extra steps to include the jedi theme and the 3 column layout ?
Postado em 01/09/11 05:10.
Nice Article Jan !!!
Postado em 29/09/11 03:08.
This smells like a hack, meaning changing files inside container's file structure.
I'm looking for a more "graceful" approach, i.e. building the portal from the source so that the installed instance will be mounted to the specified context root.
What configuration should I make before running ant deploy ?
Postado em 30/11/11 18:15.
How to get this context path inside custom portlets ? Any idea ?
Postado em 18/04/12 21:11 em resposta a Alex Leshinsky.
virtual path can be used
Postado em 07/05/12 05:18 em resposta a Manoj GT.
I have tried to localize the plugin but I can't find it (http://www.liferay.com/downloads/liferay-portal/community-plugins/-/software_ca­talog/products/8246761) does anyone have tried it with success?
Postado em 28/01/13 02:54.
i am looking for the portlet-plugin referred in his post. The link http://www.liferay.com/downloads/liferay-portal/community-plugins/-/software_cat­alog/products/8246761, doesn't work. Can somebody please help!!
Postado em 25/02/14 12:06.
Hi Rafael, were you able to get the portlet plugin?
Postado em 25/02/14 12:08 em resposta a Rafael Lluis.
You can find it on the marketplace:

https://www.liferay.com/es/marketplace/-/mp/application/30896807
Postado em 25/02/14 12:19 em resposta a Rohit Gupta.