From d10595ce324af9bf3d85f36265aba8fa5b33e9a9 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 25 Jun 2020 11:41:10 +0000 Subject: [PATCH] Canonical: Move trailing slash handling for `robots.txt` and sitemaps to a single condition. Give the unit test a more descriptive name. Follow-up to [48153], [48155]. See #48025. Built from https://develop.svn.wordpress.org/trunk@48166 git-svn-id: http://core.svn.wordpress.org/trunk@47935 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 15 ++++++--------- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index a799c5c2d3..2d776e8707 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -57,8 +57,8 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { } } - if ( is_admin() || is_search() || is_preview() || is_trackback() - || is_favicon() || ( $is_IIS && ! iis7_supports_permalinks() ) + if ( is_admin() || is_search() || is_preview() || is_trackback() || is_favicon() + || ( $is_IIS && ! iis7_supports_permalinks() ) ) { return; } @@ -655,8 +655,10 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { $redirect['path'] = trailingslashit( $redirect['path'] ); } - // Remove trailing slash for sitemaps requests. - if ( ! empty( get_query_var( 'sitemap' ) ) || ! empty( get_query_var( 'sitemap-stylesheet' ) ) ) { + // Remove trailing slash for robots.txt or sitemap requests. + if ( is_robots() + || ! empty( get_query_var( 'sitemap' ) ) || ! empty( get_query_var( 'sitemap-stylesheet' ) ) + ) { $redirect['path'] = untrailingslashit( $redirect['path'] ); } @@ -682,11 +684,6 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { $redirect['host'] = $original['host']; } - // Even if the permalink structure ends with a slash, remove slash robots.txt. - if ( is_robots() ) { - $redirect['path'] = untrailingslashit( $redirect['path'] ); - } - $compare_original = array( $original['host'], $original['path'] ); if ( ! empty( $original['port'] ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 573f2b6834..7fdecc472d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-alpha-48165'; +$wp_version = '5.5-alpha-48166'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.