[wp-trac] [WordPress Trac] #50100: Native domain mapping does not handle both WWW and non-WWW versions of a domain - both should work
WordPress Trac
noreply at wordpress.org
Wed May 13 09:26:38 UTC 2020
#50100: Native domain mapping does not handle both WWW and non-WWW versions of a
domain - both should work
--------------------------------+------------------------------
Reporter: jodamo5 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Networks and Sites | Version: 5.4.1
Severity: normal | Resolution:
Keywords: needs-testing | Focuses: multisite
--------------------------------+------------------------------
Comment (by jodamo5):
Thanks @jeremyfelt
To clarify, the [https://wordpress.org/support/article/wordpress-
multisite-domain-mapping/ WP domain mapping documentation] does not state
that multiple domains can be mapped. So the documentation is correct,
however it fails to mention the enormous problem of not handling both www
and non-www within the native domain mapping setup.
However, to update the ticket, I have investigated further, and found that
the code you mentioned does indeed work. So my second example was
incorrect.
To confirm, if the domain is mapped without www e.g. `abc.com` then if a
visitor types `www.abc.com` the domain mapping automatically finds and
swaps them to `abc.com`. So that is good.
However, the other half of the problem still exists. It is a huge
usability issue that when a domain is mapped as `www.` the bare domain
does not redirect to the site, but instead shows a multisite registration
page.
Redirecting a bare domain to www, if the www version is mapped, is
standard practise across all other domain mapping plugins - and the
documentation says we no longer need to use these other plugins since
domain mapping is now native.
I strongly expect WordPress multisite users who map `www.abc.com` as their
domain would be shocked and frustrated when `abc.com` does not redirect to
their site and instead takes users to the registration page. I know that
was my experience.
Thanks very much for pointing to the right place in the code. It was
exactly the right section for handling this problem.
I would like to propose that, to solve this usability problem, we simply
add "www." to queries for bare domains, so that both www and non-www
domains are checked. The code in ms-load.php already handles building the
array of two domains and checking if either matches an existing site, so
it would only be a small change that would greatly improve the usability.
It would mean that every domain array has two domains - a www and non-www
version.
== Proposed Change
=== Existing Code
{{{
// Either www or non-www is supported, not both. If a www domain
is requested,
// query for both to provide the proper redirect.
$domains = array( $domain );
if ( 'www.' === substr( $domain, 0, 4 ) ) {
$domains[] = substr( $domain, 4 );
}
$args = array(
'number' => 1,
'update_site_meta_cache' => false,
);
if ( count( $domains ) > 1 ) {
$args['domain__in'] = $domains;
$args['orderby']['domain_length'] = 'DESC';
} else {
$args['domain'] = array_shift( $domains );
}
}}}
=== Proposed New Code
{{{
// Whether a www or non-www domain is requested,
// query for both to provide the proper redirect.
$domains = array( $domain );
if ( 'www.' === substr( $domain, 0, 4 ) ) {
$domains[] = substr( $domain, 4 );
} else {
$domains[] = 'www.'. $domain;
}
$args = array(
'number' => 1,
'update_site_meta_cache' => false,
'domain__in' => $domains,
'orderby' => array('domain_length' => 'DESC')
);
}}}
I have tested this within a multisite environment, and it produces the
exact same array that was previously produced when a www. domain was
requested. It now produces that array whether a www or non-www domain is
requested. So the code works well. (It will of course need thorough
testing.)
I can set this up as a pull request, but first wanted to get feedback
about it.
I expect this would a barely measurable performance impact, while greatly
improving the usability of domain mapping. What are your thoughts on this
enhancement?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50100#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list