Opened 20 months ago

Last modified 7 months ago

#18734 new defect (bug)

Subcategory archive does work with any name as parent category in URL

Reported by: ocean90 Owned by:
Priority: normal Milestone: Future Release
Component: Canonical Version: 3.0.1
Severity: normal Keywords: needs-unit-tests needs-patch
Cc: dd32, juliobosk@…

Description

Parent category is parentcategory and his sub category is subcategory.

The URL will be domain.com/category/parentcategory/subcategory.

The problem is, that you will get the same page if you use any words as parentcategory.

Examples:

  • domain.com/category/xxx/subcategory
  • domain.com/category/subcategory
  • domain.com/category/foo/bar/subcategory

IMO redirect_canonical should do his work here (and sometimes it does).

In 3.1 it does redirect.
In 3.1.4 it doesn't redirect; after r17549.
In 3.2.1 it doesn't redirect.
Duck_ found that it does redirect before r18079.
In current trunk it doesn't redirect.

Change History (5)

  • Keywords needs-unit-tests added

We need tests for all the bugs the have been fixed and unfixed over time.

Related: #17174, #16627, #12659

  • Version changed from 3.1 to 3.0.1

Some more canonical tests: [UT444]

History in trunk

[13091] for original /category/child/ to /category/parent/child/ redirection.

Broken by [15462] as "The easiest one is to assume that if we had come to the right category page without any get variables, we don't need the logic for redirecting to the canonical category page. This is valid statement, because that logic relies only on removing get arguments." (#14201) is incorrect. parse_url($tax_url) ... $redirect['path'] = $tax_url['path']; is redirecting to the correct term link.

Fixed again in [15705], but re-introducing #14201. The scope of the !empty($redirect['query'] conditional was changed.

Re-broken by [18079] which moved stuff back inside !empty($redirect['query'] (also fixing #14201 again).

tl;dr: canonical isn't kicking in unless the URL has a query. This was done as a stop-gap fix for #14201.

  • Keywords needs-patch added; dev-feedback removed
  • Milestone changed from Awaiting Review to Future Release

Duck_, any idea what we can do here?

  • Cc juliobosk@… added

Waiting for a fix, i created this hack:

add_action( 'wp', 'baw_non_duplicate_content' );
function baw_non_duplicate_content()
{
	global $wp_query;
	if( isset( $wp_query->query_vars['category_name'], $wp_query->query['category_name'] )
		&& $wp_query->query_vars['category_name'] != $wp_query->query['category_name'] ):

		$correct_url = str_replace( $wp_query->query['category_name'], $wp_query->query_vars['category_name'], $wp->request );
		wp_redirect( home_url( $correct_url ), 301 );
		die();
	endif;
}
Note: See TracTickets for help on using tickets.