Making WordPress.org

Changeset 8934


Ignore:
Timestamp:
06/07/2019 04:30:34 AM (7 years ago)
Author:
dd32
Message:

Theme Directory: Make the canonical redirects for uppercase urls a little less strict.

This uses path comparisons instead to reduce the complexity.

See #4364.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-themes/functions.php

    r8933 r8934  
    5151
    5252        // Uppercase characters in URLs tend to lead to broken JS pages.
    53         // This redirects any URLs that match /$slug or /browse/$section and have an uppercase URL to the lower-case variant.
     53        // Redirect all paths to the lower-case variant, excluding searches..
     54        $path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
    5455        if (
    55                 preg_match( '![A-Z]!', $_SERVER['REQUEST_URI'] ) &&
    56                 (
    57                         preg_match( '!^/themes/[^/]*[A-Z]+!', $_SERVER['REQUEST_URI'] ) ||
    58                         '/themes/browse/' === strtolower( substr( $_SERVER['REQUEST_URI'], 0, 15 ) )
    59                 )
     56                $path &&
     57                $path !== strtolower( $path ) &&
     58                ( is_search() && trailingslashit( $path ) !== '/themes/search/' . get_query_var( 's' ) . '/' )
    6059        ) {
    61                 $url = trailingslashit( strtolower( remove_query_arg( array_keys( $_GET ), $_SERVER['REQUEST_URI'] ) ) );
     60                $url = preg_replace(
     61                        '|^' . preg_quote( $path, '|' ) . '|',
     62                        trailingslashit( strtolower( $path ) ),
     63                        $_SERVER['REQUEST_URI']
     64                );
    6265                wp_safe_redirect( $url, 301 );
    6366                die();
    6467        }
    6568
    66         // add a trailing slash to /browse/ requests
    67         if ( preg_match( '!^/themes/browse/([^/?]+)$!i', $_SERVER['REQUEST_URI'] ) ) {
    68                 $url = trailingslashit( $_SERVER['REQUEST_URI'] );
     69        // Ensure all requests are trailingslash'd.
     70        if ( $oath && '/' !== substr( $path, -1 ) ) {
     71                $url = str_replace( $path, $path . '/', $_SERVER['REQUEST_URI'] );
    6972                wp_safe_redirect( $url, 301 );
    7073                die();
Note: See TracChangeset for help on using the changeset viewer.