I suppose there’s a way to remove the offending rewrite rule from the rules array, maybe on generate_rewrite_rules
, which would result in I’m not sure what, maybe a 404, or WordPress would try to redirect to the correct URI.
or, I came up with this bit of code to check for category requests without category
in the URL, and 301 redirect them to the version with category
. It’s a bit crude, but it may work for you.
function wpa_category_requests( $request ){
if ( ! is_admin()
&& isset( $request->query_vars['category_name'] )
&& ! isset( $request->query_vars['name'] ) ){
if ( false === strpos( $request->request, 'category' ) ){
wp_redirect(
home_url( '/category/' . $request->query_vars['category_name'] . "https://wordpress.stackexchange.com/" ),
301
);
}
}
}
add_action( 'parse_request', 'wpa_category_requests' );