Hey all. The behavior of 301 redirects in CS-Cart doesn't make sense to me. There is a message on http://docs.cs-cart.com/4.4.x/user_guide/addons/seo/301_redirects.html that says:
A redirect from an object will work only if this object was not found. A disabled object still exists, even though it canâ€™t be viewed on the storefront. Thatâ€™s why the redirect from that object wonâ€™t work. But if you delete the object or change its SEO name, the redirect will work.
Curious if anyone knows how to bend that behavior to allow objects to be redirected regardless of their status? What i mean is if a product/cat/page/etc exists and has a URi redirect-this.html, i want to be able to redirect that URi using the 301 manager regardless of whether the object exists.
/app/addons/seo/func.php (fn_seo_get_route) hooks fn_get_route() in /app/functions/fn.control.php which sets $result as INIT_STATUS_REDIRECT. However, once you dig into that hook it becomes slippery to nail down. For example im hung up on a few thoughts:
- $is_allowed_url is named funny, seems confusing off the bat. If is_allowed_url is false then redirect request is true. Feels like its missing some kinda $objects['type'] check somewhere that could solve this, although everywhere i tried caused looping, or another 301 to homepage after success, or other estranged behavior due to wrong check order, lack of type, or multiple loops explained below.
- $objects array is populated with different values in different loops. Seems like there should be just 1 loop based on 1 array, not redundant checks for different styles of arrays. This lead me back to the regex, but messing with that might erase some kinda compat im not aware of as to why the other $objects array is needed.
- In a product uri like redirect-this.html there are 2 loops searching the seo_names table based on 2 variations of $objects arrays. They are looking in there for something ending in .html, however the object names are stored without the .html (even if master seo rule says append it on object url). It seems strange to go through there, essentially twice doing the same check in a different way, but maybe im missing something?
I honestly figured this would be a pretty easy fix, but after seeing the giant redir hook, all its temp array maps, and strange multiple loops, i am requesting backup :) Code 2 flow PDF attached.
Thanks for your time all.