XP virutal host and context branch in services, com.enonic.xp.web.vhost.cfg config

Enonic version: 5.3
OS: Ubuntu 14

There seem to be a bit of uncertainty when it comes to branch context when using virtual host mapping in

When mapping the root dir to a branch:

mapping.intranet.host = localhost
mapping.intranet.source = /
mapping.intranet.target = /portal/master/site

Using a service with direct addressing to the draft branch:

we still get a master branch context.

So to go around this problem, one has to define explicitly the service in com.enonic.xp.web.vhost.cfg:
mapping.service.host = localhost
mapping.service.source = /portal/draft/site//service/package.com/service
mapping.service.target = /portal/draft/site/

Then we get a draft context, when addressing /portal/draft/site/_/service/package.com/service.


What is happening here is that when you say that / on localhost is mapped to /portal/master/site you will actually get /portal/master/site/portal/draft/site/_/service/package.com/service when accessing http://localhost/portal/draft/site/_/service/package.com/service.

As you see, the correct here is that it’s under master branch. You are actually not accessing the path directly as you imagined. It’s generally not a good idea to use localhost in your virtual host mappings. Use another host name and add it to your /etc/hosts file (or C:\Windows\System32\Drivers\etc\hosts on windows).

I changed the host just as an example, the reason why we had to do the mapping was that we were actually trying to use the service outside localhost and then it failed, because it was addressing the wrong branch. Is there any way to exclude or use wildcards in virtual host config?

No, it’s not supporting any wildcards right now or exclude options.