Bachir Soussi Chiadmi 272fa07ccf updated contrib modules | 6 лет назад | |
---|---|---|
.. | ||
config | 6 лет назад | |
src | 6 лет назад | |
tests | 6 лет назад | |
README.md | 6 лет назад | |
domain_alias.info.yml | 6 лет назад | |
domain_alias.install | 6 лет назад | |
domain_alias.links.action.yml | 6 лет назад | |
domain_alias.links.task.yml | 6 лет назад | |
domain_alias.module | 6 лет назад | |
domain_alias.permissions.yml | 6 лет назад | |
domain_alias.routing.yml | 6 лет назад | |
domain_alias.services.yml | 6 лет назад |
Aliases define unique domains or patterns that map to existing domain records. For example, you may want to have the following setup:
In effect, myexample.com and my.example.com behave the same way from a Drupal perspective. Aliases may also be made to redirect to their parent domain, if preferred.
The Drupal 8 version of Domain Alias supports multi-character wildcards as part of the hostname. You can register an alias to a domain record in any of the following patterns.
*.example.com
example.*.com
example.com.*
*.*.example.com
example.*.*.com
example.*
example.*.*
example.*.*.*
*.com
*.example.*
example.com:8080
example.com:*
example.*:*
*.com:*
A maximum of three wildcards are supported. At least one element must not be a wildcard. Ports may be wildcards as well, but are optional.
When a request is sent to Drupal, the domain negotiation system will look for a matching record. The order of precedence is as follows.
Example request: one.example.com
one.example.com
)one.example.com
)Wildcard match
one.example.com
one.example.*
*.example.com
one.*.com
*.example.*
*.*.com
one.*.*,
Note that wildcard matching happens in the listed order. The number of wildcards is equal to the number of hostname parts minus 1. That is, you cannot register an alias that is all wildcards.
Port matching (e.g. example.com:8080) works exactly as hostname matching, with one significant change. If the inbound request is on port 80, matches to the base hostname are permitted, since port 80 is the default port for HTTP.
For example, a request to example.com:80 will match the following aliases:
example.com:80
example.com
example.com:*
example.*
example.*:80
example.*:*
*.com
*.com:80
*.com:*
Whereas a request to example.com:8080 will not match the hostname without a port specified.
example.com:8080
example.com:*
example.*:8080
example.*:*
*.com:8080
*.com:*
Aliases can be used to support development across different environments, with unique
URLs. To support this feature, there is now an environment
field for each alias. The
default environment list is:
This list may be overridden by setting the domain_alias.environments
configuration in
settings.php.
The operation of these environments is as follows:
default
, no changes occur.domain_alias_domain_load()
for the logic.)For instance, consider the following configuration. Your site's canonical domains are:
When developing locally, developers use .local
instead of .com
. These should be
aliased to each domain as set as the local
environment.
When pushing changes to the cloud, we use a development server. These are tied to a
specific cloud host (dev.mycloud.com). You can alias these to the development
environment.
The pattern can repeat for each of the environments listed above. The intended use of the default set of environments is:
None of these environments are required. You may safely set all aliases to default if your workflow does not span multiple server environments.
This feature works by mapping each alias to an environment. If the active request matches
an alias that is set as an environment other than default
, then matching environment
aliases are loaded for each domain. If a match is found, the hostname
value for each
domain is overwritten.
This overwrite affects the base path and request url that Domain module (and Domain Source) use for writing links.
Because the environments are specific to hostnames, this feature will only work if the
site's cache recognizes url.site
as a required cache context. Without that, the render
system will cache the output of a request incorrectly.
To use this feature, the following steps must be followed:
url.site
must be added as a required_cache_context to your services.yml
file.default
.trusted_host_settings
in settings.php
.The matching follows an explicit sort order shown in DomainAliasSortTest.
The code will attempt to match domains of different lengths when doing wildcard
matching in an environment. That is, an alias to example.*
assigned to local
should
return example.local
if the active domain is one.example.local
, assigned to local
.