I recently encountered what I thought was curious behavior from WooCommerce Products in that the URL redirected when the incorrect directory was specified.


The product base permalink is set to 'product' in settings > permalinks so that if a product called 'sample' is added then the URL is automatically set as https://example.com/product/sample/.

All of this works fine. However, if I enter the URL 'https://example.com/sample/' into the browser and I do not have a page called 'sample', then this automatically redirects to https://example.com/product/sample/. In fact if I enter any directory name like 'https://example.com/XXX/sample/' into the browser then it redirects to https://example.com/product/sample/.

I then tried this on a Wordpress page where the parent directory was specified in the page definition e.g. https://example.com/parent/page/ and again if I enter https://example.com/page/ then this redirects to https://example.com/parent/page/.

This appears to be standard Wordpress functionality that I never noticed until now, but I cannot find any information on-line about this feature not can I find if there is some way to turn this off so that there is no auto-redirect. Any suggestions or insights will be welcomed.

  • 1
    I'd guess the main page query is picking up the post by slug only, possibly set up by WP::parse_request, and then wp-includes/canonical.php is doing the redirect. But at first glance I can't see the exact code that's doing this.
    – Rup
    Oct 19, 2021 at 10:21
  • 1
    assuming this is also default behaviour for a custom post type, that is. It may still be the case that WooCommerce has extended this behaviour and this is WooCommerce-specific after all, but I'd guess not.
    – Rup
    Oct 19, 2021 at 10:24
  • WooCommerce and other 3rd party plugin/theme dev support is off topic and not in this stacks scope. You should ask via their official support routes or in their groups and communities.
    – Tom J Nowell
    Oct 19, 2021 at 10:42


Browse other questions tagged or ask your own question.