[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 6 17:58:09 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
--------------------------------+------------------------------
Changes (by jeremyfelt):

 * keywords:   => needs-testing
 * type:  enhancement => defect (bug)


Comment:

 Hi @jodamo5, thanks for opening a ticket.

 Some of my memories around this are a little fuzzy, but treating
 `www.domain.com` and `domain.com` as the same is effectively what
 WordPress does when it can and I think has helped avoid confusion overall.

 From `wp-includes/ms-load.php` ([https://github.com/WordPress/wordpress-
 develop/blob/bb526f508724eb11551be67d6985578eea8a5215/src/wp-includes/ms-
 load.php#L231-L236 code on GitHub]):

 {{{
 // 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 );
 }
 }}}

 I'm not sure why the WP [https://wordpress.org/support/article/wordpress-
 multisite-domain-mapping/ support documentation mentions native domain
 mapping]. I think that article needs to be updated with a bit more context
 as WordPress does not have native ability to map multiple domains to a
 single domain. The preferred term for what WordPress does provide support
 for is arbitrary domains.

 It used to be more difficult to use arbitrary domains in WordPress, which
 is one of the reasons that people would install a domain mapping plugin.
 Not to map multiple domains to one, but to support different full domains
 in general. In WordPress 4.5 (or earlier?), we improved support for
 arbitrary domains. This means that `example.com` and
 `unrelatedexample.com` will have an easier time on the same network.
 Telling WordPress to load `example.com` when `unrelatedexample.com` is
 requested is still something a plugin must handle.

 That all said.

 Based on the logic from `ms-load.php` above, I **would** expect your
 second example to work. If `abc.com` exists in `wp_blogs` as a site's
 `domain` and a request to `www.abc.com` is received and
 `get_site_by_path()` is fired, then it should find `abc.com` and redirect
 accordingly. If this is not working, there may be a bug to track down.

 I would not expect the first example to work as that would involve always
 adding `www` to queries for bare domains. (I think our recommendation in
 the past has been to try and avoid `www` on sites, but that could
 definitely be wrong?)

 In general, while the first example should work, and we should look at
 fixing any related bug, I would always encourage anyone to handle these
 redirects at the web server level rather than in WordPress as it removes
 the need for WordPress to handle the unnecessary query and redirect.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50100#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list