Lose ten pounds off your URL

UPDATE: I've added a 1 minute demonstration of this entire tutorial at the bottom of this blog.

There's a lot under the hood when it comes to Liferay, and even that is an understatement, but in my opinion there's one very useful feature that never gets enough play; virtual hosting.  In Liferay, virtual hosting is a free, out-of-the-box feature used to host more than one domain name on the same IP address, like running www.a.com, www.b.com, and www.c.com all running on one copy of Liferay.  Cool, right?  So, let me show you how to set up virtual hosting on your machine, because it should only take 5 minutes.

First, setup your machine to force some domain names redirect to your local copy of Liferay.  This step involves editing the hosts file on your machine, and it is only for testing purposes, so it won't actually change the way anyone else in the world sees these domains.

To do this in Windows, go to the %WINDIR%\System32\drivers\etc directory and open the hosts file in Notepad.  To do this in Mac OS, go to the /etc directory and open the hosts file in TextEdit.  If you're running Linux, well, you should already know how to do this.  Once the file is opened, add the following entry on a new line:

127.0.0.1       www.alpha.com

Next, startup Liferay and test the new domain.  Visiting http://localhost:8080/ should redirect you to http://localhost:8080/web/guest/ and you should see your local copy of Liferay.

Much the same, visiting http://www.alpha.com:8080/ should redirect you to http://www.alpha.com:8080/web/guest/, just like localhost.

Now it's time to map a new community to www.alpha.com.  The first step is to add a new community, so go to the Control Panel, and from there go to the Portal > Communities page.  At the top you'll see an Add button, click it and add a new community named Alpha.

Once the Alpha community has been created the second step is to go to Manage Pages by clicking the Actions button and selecting Manage Pages.  You'll need to add at least one page to your new community, so add a new page named Home.  Once this is done, click on the Settings tab.  In settings, click on the Virtual Host tab and you will see an empty field labeled Public Virtual Host.  Add the domain www.alpha.com here and click Save.

Now if you visit http://www.alpha.com:8080/ and you should see the Alpha community, without any pesky /web/guest in the URL.

That's it!  Now you're using virtual hosting on your machine, and your website just lost ten pounds.

And for the truly visual, I've made a video highlighting the entire process in just one minute and in one continuous shot.

Jonathan

P.S: If you didn't notice, you can map any number of domains and even sub-domains (xyz.a.com) to your site, but as far as I can tell Liferay does not yet support multiple domain mapping on the same community or wildcards, which means I'll be bugging our developers for the next few weeks.

Blogues
Yes great feature, we're using it for quite some time now. The multiple virtual hosts would be a great improvement. Maybe you can take multilanguage into account too? If you reach a site with a certain hostname, show the website in a specific language.
Nice - and just in time (for me). This also works when liferay doesn't live in "/" but - e.g. - in "/cms". We use Apache and mod_jk and have some static content that is served by apache, so in order to ease mapping of directories we have relocated liferay from "/" to "/cms" (or, in other instances, to different directories)

With mod_jk in place virtual hosting seems to work well - apart from the occasional glitches (see http://issues.liferay.com/browse/LPS-3210 and http://issues.liferay.com/browse/LPS-3482 - note: both issues are unrelated to virtual hosts but related to deploying to a location other than "/").

Just add your liferay-deployment-directory to the path and you have a nice URL as well.
speaking about glitches: Be aware of i18n issues with the url (or your friendly url) - they don't work well together:

http://issues.liferay.com/browse/LPS-4398

Luckily the quickfix is to just choose another friendly url. Just have to remember this fix for StringIndexOutOfBoundsException, but if you don't know this, it is quite a show stopper.
We've had some problems with the URL-generation when using VirtualHost aswell, seems like the VirtualHost-parts haven't been as well tested as the rest of the Portal. In addition to the above mentioned 3210 i've had the following problem http://issues.liferay.com/browse/LPS-3626 with wiki-links missing whitespaces when using Virtual Hosts.
Hi I have a question

If we use a site with context e.g. http://www.mydomain.com/myroot/web/guest/home
Now if need to remove /web/guest here
what should be done?
I also have written an article about virtual host:
http://atitudereflexiva.wordpress.com/2012/11/02/configuracao-de-urls-no-liferay/
Furthermore, there are some tips on breadcrumb problem.
Great Post Jonathan ,
Liferay Portal is simply Awesome and love the Direction and the way it is going.

as liferay give so much for the community( i mean virtualhost, managepages) feature why not authentication setup for community. because different community comes from different urls looks like different site share the information in the backend. for Liferay portal administrator community based authentication feature is going to be so much helpful and ofcourse for Liferay also.