• Resolved Vini

    (@vinieaffini)


    Hi! i found today strange behaviour.

    Our shop page have problem with “category links”.

    Example:
    We have category “child-category” with path:
    https://www.example.pl/category-page/main-category/child-category

    But for some reason we can also use:
    https://www.example.pl/category-page/here-you-can-write-anythingsjjdjdjdjdjdjdjddj/child-category
    https://www.example.pl/category-page/xxxxx-ttttt-ddddd/child-category
    And there is no redirect to: https://www.example.pl/category-page/main-category/child-category

    All this links show page/duplicate? /category-page/no-matter-what-is-here/child-category

    Is it normal in wordpress/woocommerce or it’s works wrong? is easy way to fix this?

    Chatgpt suggest add to wpcode this php… but i’m not sure…

    add_action(‘template_redirect’, function () {

    if (is_admin() || wp_doing_ajax() || wp_doing_cron()) {
        return;
    }
    
    if (empty($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] !== 'GET') {
        return;
    }
    
    // Nie ruszamy adresów z parametrami, np. filtrowania, sortowania, UTM-ów.
    if (!empty($_GET)) {
        return;
    }
    
    // Nie ruszamy kluczowych stron WooCommerce.
    if (
        function_exists('is_cart') && is_cart() ||
        function_exists('is_checkout') && is_checkout() ||
        function_exists('is_account_page') && is_account_page()
    ) {
        return;
    }
    
    $canonical_url = '';
    
    // Strony, wpisy, produkty i inne pojedyncze typy treści.
    if (is_singular()) {
        $object_id = get_queried_object_id();
    
        if ($object_id) {
            $canonical_url = get_permalink($object_id);
        }
    }
    
    // Kategorie produktów, kategorie wpisów, tagi i inne taksonomie.
    if (is_tax() || is_category() || is_tag()) {
        $term = get_queried_object();
    
        if (
            $term &&
            !is_wp_error($term) &&
            !empty($term->term_id) &&
            !empty($term->taxonomy)
        ) {
            $canonical_url = get_term_link((int) $term->term_id, $term->taxonomy);
        }
    }
    
    if (!$canonical_url || is_wp_error($canonical_url)) {
        return;
    }
    
    $current_path = trailingslashit(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
    $canonical_path = trailingslashit(parse_url($canonical_url, PHP_URL_PATH));
    
    if ($current_path !== $canonical_path) {
        wp_safe_redirect($canonical_url, 301);
        exit;
    }

    }, 1);

    But maybe we are missing something in settings? any help?

    • This topic was modified 4 days, 21 hours ago by Vini.
Viewing 1 replies (of 1 total)
  • Plugin Support Tanjir Al Mamun

    (@tanjiralmamun)

    Hi @vinieaffini,

    This is standard WordPress behavior. WooCommerce product category (and standard category) URLs are resolved by the final term slug only. The parent path in the URL is used for the permalink readability, but WordPress doesn’t validate it during routing, so /category-page/anything/child-category will load the same page as the canonical URL without redirecting.

    The PHP snippet ChatGPT suggested is a reasonable way to enforce canonical redirects. One thing to be aware of: the if (!empty($_GET)) { return; } guard means any URL containing query parameters (filters, sorting, UTM tags) will be skipped entirely, and no redirect will fire. That’s likely intentional to avoid breaking filtered pages, but worth confirming based on your setup.

    This behavior isn’t something Product Feed Pro controls — it’s at the WordPress/WooCommerce level. For help enforcing canonical redirects on your category URLs, I recommend reaching out to the WooCommerce support team directly. They’ll be best placed to advise on the right approach for your setup.

    Thanks!

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.