SiteAccess matching¶
To be usable, every SiteAccess must be matched by one of configured matchers.
By default, all SiteAccesses are matched using URIElement: 1.
You can configure SiteAccess matchers under the ibexa.siteaccess.match configuration key:
1 2 3 4 5 6 7 8 9 10 | |
ibexa.siteaccess.match can contain multiple matchers.
The first matcher succeeding always wins, so be careful when using catch-all matchers like URIElement.
In the following example, Compound\LogicalAnd is placed before the Map\Host for my.site/corporate to be reachable:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
If the matcher class doesn't start with a backslash (\), it's relative to Ibexa\Core\MVC\Symfony\SiteAccess\Matcher (for example, Map\URI refers to Ibexa\Core\MVC\Symfony\SiteAccess\Matcher\Map\URI)
You can specify custom matchers by using a fully qualified class name (for example, \My\SiteAccess\Matcher) or a service identifier (for example, @my_matcher_service).
In the case of a fully qualified class name, the matching configuration is passed in the constructor.
In the case of a service, it must implement Ibexa\Bundle\Core\SiteAccess\Matcher.
The matching configuration is passed to setMatchingConfiguration().
Available SiteAccess matchers¶
URIElementURITextHostElementHostTextMap\HostMap\URIMap\PortIbexa\SiteFactory\SiteAccessMatcher
URIElement¶
Maps a URI element to a SiteAccess.
In configuration, provide the element number you want to match (starting from 1).
1 2 3 4 | |
Note
When you use a value > 1, the matcher concatenates the elements with _.
Example URI /my_site/company/pages matches SiteAccess my_site_company.
URIText¶
Matches URI using prefix and suffix sub-strings in the first URI segment.
In configuration, provide the prefix and/or suffix (neither is required).
1 2 3 4 5 6 | |
Example URI /main-event/company/page matched SiteAccess event.
HostElement¶
Maps an element in the host name to a SiteAccess.
In configuration, provide the element number you want to match (starting from 1).
1 2 3 4 | |
Example host name www.example.com matches SiteAccess example.
HostText¶
Matches a SiteAccess in the host name, using pre and/or post sub-strings.
In configuration, provide the prefix and/or suffix (none are required).
1 2 3 4 5 6 | |
Example host name www.example.com matches SiteAccess example.
Map\Host¶
Maps a host name to a SiteAccess.
In configuration, provide a hash map of host/SiteAccess.
1 2 3 4 5 6 | |
Example host name www.page.com matches SiteAccess event.
Note
If you encounter problems with the Map\Host matcher, make sure that your installation is properly configured to use token-based authentication.
Map\URI¶
Maps a URI to a SiteAccess.
In configuration, provide a hash map of URI/SiteAccess.
1 2 3 4 5 6 | |
Example URI /campaign/general/articles matches SiteAccess event.
Map\Port¶
Maps a port to a SiteAccess.
In configuration, provide a hash map of Port/SiteAccess.
1 2 3 4 5 6 | |
Example URL http://my_site.com:8080/content matches SiteAccess site.
Ibexa\SiteFactory\SiteAccessMatcher ¶
Enables the use of Site Factory. Doesn't take any parameters in configuration:
1 2 3 4 | |
Custom matchers¶
Beside the built-in matchers, you can also use your own services to match SiteAcceses:
1 2 3 4 5 6 7 8 | |
The service must be tagged with ibexa.site_access.matcher and must implement Ibexa\Bundle\Core\SiteAccess\Matcher (and Ibexa\Core\MVC\Symfony\SiteAccess\VersatileMatcher if you want to use compound logical matchers).
Combining SiteAccess matchers¶
You can combine more than one SiteAccess matcher to match more complex situations, for example:
http://example.com/enmatchessite_en(match host example.com and theenURI element)http://example.com/frmatchessite_fr(match host example.com and thefrURI element)http://admin.example.commatchessite_admin(match host admin.example.com)
To combine matchers, use compound logical matchers:
Compound\LogicalAndCompound\LogicalOr
Each compound matcher specifies two or more sub-matchers. A rule applies if all the matchers combined with the logical matcher are positive.
To get the result above, you need to combine Map\Host and Map\Uri using LogicalAnd.
When both the URI and host match, the SiteAccess configured with match is used.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
When using Compound\LogicalAnd, all inner matchers must match.
All matchers must implement VersatileMatcher.
When using Compound\LogicalOr, the first inner matcher succeeding wins.
Matching by request header¶
You can define which SiteAccess to use by setting an X-Siteaccess header in your request.
This can be useful for REST requests.
In such a case, X-Siteaccess must be the SiteAccess name (for example, site or en).
Matching by environment variable¶
You can also define which SiteAccess to use directly by using the EZPUBLISH_SITEACCESS environment variable.
This is recommended if you want to get performance gain since no matching logic is done in this case.
You can define this environment variable directly in web server configuration:
1 2 3 4 5 6 7 8 | |
Tip
You can configure the variable by using the PHP-FPM configuration file. For more information, see PHP-FPM documentation.
Precedence
The precedence order for SiteAccess matching is the following (the first matched wins):
- Request header
- Environment variable
- Configured matchers