Support » Plugin: WooCommerce » Product url

  • Resolved atomonelone

    (@atomonelone)


    So I have a dilemma and I’m not sure if I’ve done something wrong or if its intended to be like this.

    My product urls are structured like this: example.com/products/category/productslug/ Now if I go to a product and change the url to something like this: example.com/products/cate/productslug/ Please note that it could be any variations where the category is changed aslong as there is one letter in the category part of the url. Then it will not give me a 404 error or redirect me to the normal url. In other words I will still be on the product page but the url will stay as it’s typed.

    Changing /products/ or /productslug/ will give me a 404 error.

    If I go to a normal post and do the same thing (they are structered like this: /category/postslug/) then I will be redirected to the right url. So for example changing example.com/news/postslug/ to example.com/n/postslug/ I will be redirected to the original url.

    I’ve been working a long time with wordpress and woocommerce and have never noticed this behavior before and I’m not sure if it’s intended to be like this or if something is wrong with my rewrite rules.

    Any clarification about this would be greatly appreciated.

    Thanks in advance!

    • This topic was modified 4 months, 2 weeks ago by atomonelone.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Pepe (woo-hc)

    (@anastas10s)

    Howdy @atomonelone, thank you for reaching out about this.

    Just to clarify

    My product urls are structured like this: example.com/products/category/productslug/

    This is set under Settings > Permalinks, in the WordPress backend. Correct?

    Now if I go to a product and change the url to something like this: example.com/products/cate/productslug/

    Is this altered in the browser’s address field, or elsewhere? Kindly elaborate further on where and why this is changed, please. What is the use case?

    From what I gather, you are noticing this behavior only on product URLs, and not on Post URLs.

    We will be standing by for your response.

    Thread Starter atomonelone

    (@atomonelone)

    Yes that is set under Settings > Permalinks.

    Yes, it’s altered in the browser’s address field.
    I tried changing it myself because I noticed google was indexing products on my site with very strange urls like example.com/products/n/e/l/22255/productslug witch does not exist. Not any of the categories exist but still you can enter the product.

    The thing is as long as the url is structered like this: example.com/products/random/productslug then you will access the product with the entered url.
    You could even make it how ever long you’d want it like: example.com/products/random/random/random/random/productslug and I’ll get to the product without a redirection or 404 error, just straight to the product page with the entered url.

    I tried this on 4 different woocommerce sites and it’s the same on all of them.

    Shouldn’t the intended behavior be to throw a 404 error or redirect to the actual product url instead of showing the altered url in the browser?

    You can even do this with product categories if it’s a subcategory.
    Like this: example.com/product-category/random/subcategory

    • This reply was modified 4 months, 1 week ago by atomonelone.
    • This reply was modified 4 months, 1 week ago by atomonelone.
    • This reply was modified 4 months, 1 week ago by atomonelone.
    Thread Starter atomonelone

    (@atomonelone)

    So to clarify some more, I need to know if this is the intended behavior or if I need to file a bug report about this somewhere?

    Either way I’m also wondering if you have a solution for it to stop behaving like this. It’s causing me alot of headache with my preloaded cache and SEO.

    Could I for example make a rewrite rule that always redirects to the correct url of the products, just like the normal behavior is with WordPress posts?

    Best regards.

    Plugin Support Pepe (woo-hc)

    (@anastas10s)

    Hi there @atomonelone

    Thank you for reaching back, with further information on this. What’s more, what you’re reporting can be replicated.

    While investigating further, I came across the following issues, already submitted on GitHub:

    Therefore, my suggestion would be to submit a GitHub issue about this, as it would be viewed by the developers of the plugin.

    Feel free to submit one, via the following link:

    https://github.com/woocommerce/woocommerce/issues/new/choose

    I trust that points you in the right direction, but if you have more questions, let us know. We’re happy to help.

    Thread Starter atomonelone

    (@atomonelone)

    Hi @anastas10s

    Thanks for getting back to me. After some further digging I noted that this behavior should be taken care of by WordPress native function called redirect_canonical, you can read about it here: redirect_canonical() | Function | WordPress Developer Resources

    Either way this is not happening on my website and also seems to be the problem for alot of other people. I eventually found this piece of code that takes care of it:

    function canon_redirect_can() {
    	if ( is_single() ) {
            global $wp;
    		$wp->parse_request();
            $current_url = trim(home_url($wp->request), "/");
            $redirect = get_permalink();
            $surl = trim($redirect, "/");      
    			if($current_url != $surl){
    				wp_redirect( $redirect, 301 );
    			exit;
    			}
    	}
    }
    add_action( 'template_redirect', 'canon_redirect_can' );

    I’m leaving it here if anyone stumbles upon this thread and is looking for a solution to the same problem.

    Roxy

    (@roxannestoltz)

    Hi @atomonelone ,

    That is great to hear, and thanks for sharing your workaround, this will be very helpful for others that would like an immediate fix!

    I’m going to mark this as resolved then, however, please feel free to create a new topic if you need further help 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.