Lesson 2.1: Matching by URL path
Every request is matched to one siteaccess before anything else happens. The simplest rule, and the one a default
installation uses, takes the first part of the path: /site_b/... belongs to site_b. This lesson explains that
rule, the fallback when nothing matches, and PathPrefix, which lets a site hide its own folder from its addresses.
At a glance
| Course | Multisite and site packages |
| Module | Module 2: Matching requests to siteaccesses |
| Duration | 50 minutes (20 presenting, 30 exercise) |
| Level | Intermediate |
| Audience | Administrators and developers |
| Prerequisites | Module 1: the siteaccesses site_b and site_b_ger work |
Learning objectives
After this lesson, learners can:
- explain
MatchOrderas a list of probes tried in order, the first match winning; - describe the URI match types
element,map,textandregexp; - predict which siteaccess answers an address, including one that no probe matches (
DefaultAccess); - set
PathPrefixso that the pages of a site are addressed without the site's folder name.
Trainer's notes
How to present it
Sources: the comments of settings/site.ini [SiteAccessSettings] and
10.2 Siteaccesses and site addresses.
Probes in order (5 minutes).
MatchOrderlists the probes:uri,host,host_uri,portandservervar. The shipped value isuri;host;port; the installer writes its own. The first probe that finds an available siteaccess wins; a probe that finds a name that is not inAvailableSiteAccessList[]does not count, and the next probe is tried.The URI probe (6 minutes).
URIMatchTypechooses how:Value Meaning element(shipped)the path element URIMatchElement(1, the first) is the siteaccess namemapURIMatchMapItems[]=uri;siteaccessentries map a path element to a siteaccesstexta pre or post sub-string of the path regexpa regular expression and the part it extracts disabledno URI matching With
element, the matched element is removed from the path the kernel sees, so/site_b/newsis the pagenewsofsite_b.When nothing matches (3 minutes).
[SiteSettings] DefaultAccessanswers.RemoveSiteAccessIfDefaultAccess=enabledleaves the name of the default siteaccess out of the links it builds; the comment insettings/site.inisays that changing it requires clearing the cache. Lesson 2.4 shows a better tool for the start page: the redirect to the language.PathPrefix(6 minutes). A site whose root is a folderSite Bwould otherwise have addresses such as/site_b/Site-B/an-article.PathPrefix=Site-Bin that siteaccess hides the prefix:/site_b/an-article.PathPrefixExclude[]lists paths (for examplemedia,users) that keep their full address. The comment insettings/site.iniadds that aPathPrefixalso needs thePathPrefixsetting inlogfile.ini.
Common questions
Is the name in the address the siteaccess name? With element, yes. With map, the address part and the
siteaccess name can differ, for example URIMatchMapItems[]=de;site_b_ger.
Can the main site have no prefix at all? Yes: make it the DefaultAccess, so / and every address that no
probe matches go to it, and consider the redirect of lesson 2.4.
Is URL matching good for production? It works behind any web server with one host name. Host matching (lesson 2.2) is the usual choice for production with several brands.
Why does /admin still work after I changed URIMatchType? The administration is often reached by another
probe or another entry; read MatchOrder and the map with exp:ini where.
Pitfalls
- Global changes on a shared lab.
MatchOrderandURIMatchTypelive in the global override. On a shared training server one learner's change breaks everybody's addresses. This lesson's changes are per siteaccess. - The wrong alias for
PathPrefix. The value is the URL alias of the folder as the browser shows it (case and dashes included), not its name. - Stale pages. After a
PathPrefixchange, clear the INI and content caches, or old links stay in cached pages.
Hands-on exercise
Use your training installation from module 1 (URL matching).
Read the probes and the URI rule in effect:
php bin/php/console exp:ini get site.ini/SiteAccessSettings/MatchOrder php bin/php/console exp:ini get site.ini/SiteAccessSettings/URIMatchType php bin/php/console exp:ini get site.ini/SiteSettings/DefaultAccessPredict, then check with
curl -sIand in the browser, which siteaccess answers each address (use your lab's address):/site_b,/site_b_ger,/admin,/no_such_site,/.For
/no_such_site, explain what answered: the probe found a name that is not available, so the default siteaccess took the request and treatedno_such_siteas a page address.In the administration, below the folder Site B, create and publish a Folder named
News.Open
/site_bin the browser and follow the link to News, or open the folder Site B on the main site. Note the URL alias of Site B in the address (for exampleSite-B).Set the prefix for
site_band clear the caches:php bin/php/console exp:ini set site.ini/SiteAccessSettings/PathPrefix Site-B siteaccess:site_b php bin/php/ezcache.php --clear-tag=ini php bin/php/ezcache.php --clear-id=contentOpen
/site_b/News. Then open/site_b/Site-B/Newsand compare.Look at the link to News on the start page of
/site_b: does it still carrySite-B?Undo the change if your trainer asks you to:
php bin/php/console exp:ini rem site.ini/SiteAccessSettings/PathPrefix siteaccess:site_b, then clear the caches again.
Expected result
- Step 2:
/site_band/site_b_geranswer with their own site names,/adminshows the sign-in page,/no_such_siteanswers from the default siteaccess (usually a "not found" page there), and/shows the default siteaccess's start page. - Step 7:
/site_b/Newsshows the folder News; the links onsite_b's pages no longer containSite-B. - The trainer checks by asking each learner to state, before pressing Enter, which siteaccess will answer
/site_b_ger/News, and then confirming it in the browser.
Quiz
- What does
MatchOrder=uri;host;portmean? - With
URIMatchType=element, which siteaccess answers/site_b/news? A.siteB.site_bC.newsD. theDefaultAccess - A probe finds the name
shop, which is not inAvailableSiteAccessList[]. What happens next? - What does
PathPrefixchange? - Which setting lists paths that keep their full address despite a
PathPrefix?
Answers
- The kernel tries the URI probe first, then the host probe, then the port probe; the first that finds an available
siteaccess wins (
settings/site.ini). - B. The first path element names the siteaccess, and the kernel then serves
newsin it. - The probe does not count; the next probe is tried, and when none matches,
DefaultAccessanswers. - It hides that part from the start of URL aliases for the siteaccess, so the site's own folder does not appear in
its addresses (comment in
settings/site.ini). PathPrefixExclude[].
Further reading
- 10.2 Siteaccesses and site addresses.
- URL aliases and nice URLs: how aliases are made.
- URLs and aliases: the administrator's reference.
- Going live: hosts, HTTPS and siteaccesses.
Related pages
- Module 2: Matching requests to siteaccesses
- Multisite and site packages: course overview
- Trainers: start here
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.