« 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 添付ファイル
38845 参照数
平均 (2 投票)
平均評価は4.5星中の5です。
コメント
コメント 作成者 日時
Hi, Our client requirement is to have two... Balaji Murugesan 2011/08/03 0:08
Hi Balaji, I think this should be no problem.... Jan Gregor 2011/08/05 5:28
Hi, after trying to change the context path... Inge Klein 2011/09/01 5:10
Nice Article Jan !!! Jignesh Vachhani 2011/09/29 3:08
This smells like a hack, meaning changing files... Alex Leshinsky 2011/11/30 18:15
How to get this context path inside custom... Manoj Satyagi 2012/04/18 21:11
virtual path can be used Gowtham Mani 2012/05/07 5:18
I have tried to localize the plugin but I can't... Rafael Lluis 2013/01/28 2:54
Hi Rafael, were you able to get the portlet... Rohit Gupta 2014/02/25 12:08
You can find it on the marketplace: ... Rafael Lluis 2014/02/25 12:19
i am looking for the portlet-plugin referred in... Rohit Gupta 2014/02/25 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
投稿日時:11/08/03 0:08
Hi Balaji,

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

Regards,
Jan.
Balaji Murugesanへのコメント。投稿日時:11/08/05 5:28
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 ?
投稿日時:11/09/01 5:10
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 ?
投稿日時:11/11/30 18:15
How to get this context path inside custom portlets ? Any idea ?
Alex Leshinskyへのコメント。投稿日時:12/04/18 21:11
Manoj GTへのコメント。投稿日時:12/05/07 5:18
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?
投稿日時:13/01/28 2: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!!
投稿日時:14/02/25 12:06
Hi Rafael, were you able to get the portlet plugin?
Rafael Lluisへのコメント。投稿日時:14/02/25 12:08
You can find it on the marketplace:

https://www.liferay.com/es/marketplace/-/mp/application/30896807
Rohit Guptaへのコメント。投稿日時:14/02/25 12:19