WordPress.org

Making WordPress.org

Changeset 8920


Ignore:
Timestamp:
06/05/2019 05:21:36 AM (6 months ago)
Author:
dd32
Message:

Theme Directory: Add canonical redirects for upper-case requests for Themes or section filters to their lower-case variant. The JS is case-sensitive.

Fixes #4364.

File:
1 edited

Legend:

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

    r8896 r8920  
    2727    remove_action( 'template_redirect', 'wp_old_slug_redirect' );
    2828
    29     add_action( 'template_redirect', 'wporg_themes_trailing_slashes' );
     29    add_action( 'template_redirect', 'wporg_themes_canonical_redirects' );
    3030
    3131    add_theme_support( 'wp4-styles' );
     
    3434
    3535/**
    36  * Handle the root-level redirect to trailing-slash'd uri which redirect_canonical() usually does.
    37  */
    38 function wporg_themes_trailing_slashes() {
     36 * Handle redirects which redirect_canonical() usually would (or should) do.
     37 */
     38function wporg_themes_canonical_redirects() {
     39    // always include the trailing slash for the Site URL
    3940    if ( '/themes' === $_SERVER['REQUEST_URI'] ) {
    4041        wp_safe_redirect( '/themes/', 301 );
     
    4243    }
    4344
     45    // We don't need any urls such as /themes/index.php/twentyten/ working
    4446    if ( false !== stripos( $_SERVER['REQUEST_URI'], '/index.php' ) ) {
    4547        $url = str_ireplace( '/index.php', '/', $_SERVER['REQUEST_URI'] );
     48        wp_safe_redirect( $url, 301 );
     49        die();
     50    }
     51
     52    // 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.
     54    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        )
     60    ) {
     61        $url = trailingslashit( strtolower( remove_query_arg( array_keys( $_GET ), $_SERVER['REQUEST_URI'] ) ) );
     62        wp_safe_redirect( $url, 301 );
     63        die();
     64    }
     65
     66    // add a trailing slash to /browse/ requests
     67    if ( preg_match( '!^/themes/browse/([^/]+)$!i', $_SERVER['REQUEST_URI'] ) ) {
     68        $url = trailingslashit( $_SERVER['REQUEST_URI'] );
    4669        wp_safe_redirect( $url, 301 );
    4770        die();
Note: See TracChangeset for help on using the changeset viewer.