Making WordPress.org

Ticket #2755: 2755.patch

File 2755.patch, 1.2 KB (added by gibrown, 6 years ago)

Add 404 redirect to search

  • plugins/plugin-directory/class-plugin-directory.php

     
    10151015                        $path = explode( '/', $_SERVER['REQUEST_URI'] );
    10161016
    10171017                        if ( 'tags' === $path[2] ) {
    1018                                 if ( isset( $path[3] ) ) {
     1018                                if ( isset( $path[3] ) && !empty( $path[3] ) ) {
    10191019                                        wp_safe_redirect( home_url( '/search/' . urlencode( $path[3] ) . '/' ) );
    10201020                                        die();
    10211021                                } else {
     
    10421042                                die();
    10431043                        }
    10441044
    1045                         // Otherwise, handle a plugin redirect.
     1045                        // Handle any plugin redirects.
    10461046                        if ( $path[2] && ( $plugin = self::get_plugin_post( $path[2] ) ) ) {
    10471047                                $permalink = get_permalink( $plugin->ID );
    10481048                                if ( parse_url( $permalink, PHP_URL_PATH ) != $_SERVER['REQUEST_URI'] ) {
     
    10501050                                        die();
    10511051                                }
    10521052                        }
     1053
     1054                        //Otherwise, let's redirect to the search page
     1055                        if ( isset( $path[2] ) && !empty( $path[2] ) ) {
     1056                                wp_safe_redirect( home_url( '/search/' . urlencode( $path[2] ) . '/' ) );
     1057                                die();
     1058                        }
    10531059                }
    10541060
    10551061                // If it's an old search query, handle that too.