Make WordPress Core


Ignore:
Timestamp:
08/16/2026 04:55:59 PM (3 weeks ago)
Author:
joedolson
Message:

Rewrite Rules: Only a leading www. is optional in url_to_postid().

Fixes the behavior of url_to_postid(), which treated a www. string anywhere in the URL as optional, breaking some URLs. Anchor the string so that is only considered optional when at the beginning of a URL string.

Follow up to [63207].

Props youknowriad, johnbillion, wildworks, irozum, joedolson.
Fixes #65016.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rewrite.php

    r61444 r63307  
    503503
    504504        if ( is_string( $url_host ) ) {
    505                 $url_host = str_replace( 'www.', '', $url_host );
     505                // Only a leading 'www.' is optional. Removing it anywhere else would match a different host.
     506                $url_host = preg_replace( '|^www\.|', '', $url_host );
    506507        } else {
    507508                $url_host = '';
     
    511512
    512513        if ( is_string( $home_url_host ) ) {
    513                 $home_url_host = str_replace( 'www.', '', $home_url_host );
     514                $home_url_host = preg_replace( '|^www\.|', '', $home_url_host );
    514515        } else {
    515516                $home_url_host = '';
Note: See TracChangeset for help on using the changeset viewer.