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 now, 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. In 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, your 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 ot portal. This renaming causes, that your portal will be accessible under 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 by you 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:
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 following line here:
So, that's it your portal was now migrated to new context path and you can start the application server. After start 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!