• Disclosure: Question also asked on Stack Overflow, but I figured here would possibly be a better place.

    I stumbled upon a weird problem today, and I need some pointers for where I can look for the source of the problem. This has also happened briefly one time before, with no apparent changes to the site beforehand. It is a WordPress install with WooCommerce. I know it’s hard to troubleshoot like this, but if anyone has any pointers what so ever, I would be immensely grateful.

    We suddenly found our custom taxonomy “brand” (for the WooCommerce product custom post type) redirected to other pages matching the name, much like WordPress does when you have a typo in the URL.

    /brand/brand-name/ was suddenly redirecting to /wp-content/uploads/2020/03/brand-name.png, and /brand/other-brand/ was suddenly redirecting to /wp-content/uploads/2020/03/other-brand.mp4.

    This happened regardless of clicking a link to the brand on the site, or visiting it directly in incognito mode in the browser. I contacted my host, and they say redirections are not cached, so this was generated on the fly from PHP or other code. It was just like the taxonomy did not exist, and WordPress was trying to help with redirecting to a page matching the name.

    I went into my permalinks and saved them, and the error suddenly disappeared. I have no idea how to provoke it or where I should start looking for the cause. The taxonomy is registered in the file functions.php like this:

    // Add brand taxonomy to products
    function so_brand_tax()
    {
        register_taxonomy('brand', array('product'), array(
            'label'        => 'Brands',
            'rewrite'      => array('slug' => 'brands', 'hierarchical' => true),
            'hierarchical' => true
        ));
    }
    add_action('init', 'so_brand_tax', 0);

    The permalink structure is set to custom, and then just /%postname%/.

    This is something that I have noticed only once before, and the problem disappeared with saving permalinks. I don’t like having things like this happen and not being able to explain to anyone why they are happening and what I am doing to solve the problem. This is a pretty serious error based on the amount of money spent on ads to these exact pages per month.

    There had been no plugin updates or other major changes before any of the two events, at least that I know of.

    I have been tipped by others that have had this happen, that one should not name files the same as taxonomies, because they basically get the same slug. I am open to this, but sceptical, because that seems like bad programming design, don’t you think?

    /brands/brand-name/ is not the same as /uploads/2020/03/brand-name.png. By that logic, a web designer that has a site with the page /services/logo/ would have their page redirected to /uploads/2020/03/logo.png that shows their site logo as an image? I can’t think that would be the case.

    It’s a site with 10 000 products and probably 300 000 media files. There is no way to control that no one uploads a file with the same name as a brand across all the possible file upload sites on the system…

    What could I do next? Is there any documentation on how WordPress handles these redirections? Or indeed, a best practice to never have a file named the same as a taxonomy or post?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    Thanks for your speedy reply! The discussion on the Stack Overflow forum is interesting. The problem is very similar though I do not have enough information to affirm that they are the same.

    In our case, all URLs were redirected to domain-name/blog, even though “blog” does not appear in any of the slugs.

    As to what provoked the error, I had done a Linux update in the morning though I cannot say that this created the error.

    Thread Starter Dekadinious

    (@dekadinious)

    It’s very interesting, but I have not found any reason or solution right now. The best I could do was set up an alert if the affected pages are redirected again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom taxonomy suddenly redirects to another page’ is closed to new replies.