
Originally Posted by
lhungil
When categories or products are moved around (or linked), no need to do anything special. When done, just reset the URL cache (if enabled) to see the changes immediately. As long as the product ID and Category ID are not changed, both the old and new locations will be handled automatically without any issues. Additionally, the generated canonical will contain the new URL (unless your theme disables the canonical link handling built into Zen Cart). One can also enable automatic redirects to force a 301 redirect to the new URL (if desired).
Let me first put on my "SEO Hat" and place it on my head.
From an SEO perspective, I would strongly recommend against this approach. Redirecting multiple different pages with different content to a single page (also with different content compared to the original pages) can result in a mess (or even a nightmare). Sends chills up and down my spine when I hear thoughts along these lines... But carry on if this is NOT what you are talking about...
Now let me take of the "SEO Hat" and instead put on my "Customer Hat".
Let's say six moths ago I ordered a "green widget". I was very happy with the "green widget" and now want to order another matching widget (or share a link to the product I bought with a friend). So I go back to the store, sign into my account, and pull up my order history. My expectation is I will be able to view my past order and click on a link to the "green widget" previously ordered.
If the product has been deleted from the store... This link (if enabled) brings me to a 404... Or worse, it brings me to the home page of the store (or some other page such as a category)... And in the second case, now I am confused (because I clicked on a link for a "green widget" and was brought somewhere else). Either way I no longer have a way to quickly (and easily) review the product details or specifications for the "green widget" I previously purchased... So now even if I find a new version of a product (or a similiar product) at the store, I do not have the information about the "green widget" I purchased to look at and compare against... Not the best experience...
Now if the product is still present in the store... The link does bring me to the old products page. And ideally, the store owner has made some minor edits to the product. For example: setting the product so it cannot be added to the shopping cart, added big bold obvious text letting me know the product is no longer available, added a link to the replacement (or comparable product), etc. Not only can I still review the information and details regarding my previously purchased "green widget"... But I also know the product is no longer available (and have a link to view or purchase a comparable / replacement product matching my "green widget"). For me this would be a good customer experience.
Now let me take of the "Customer Hat" and instead put on my "Consultant Hat".
The above code to dynamically redirect deleted product pages to their category is flawed. It will affect all "product pages" where a product_id is not present in the database including pages for products which never existed (and should generate a 404). There is no guarantee $_GET['cPath'] will be present (this is true even with stock Zen Cart URLs), so in some cases it will redirect to the store root instead of the expected parent category. The code fails to call zen_href_link (failing to call this may in some cases cause the customer session to be lost). The code directly access $_GET (I would avoid this), the variable $cPath will already be populated by Zen Cart and contain the correct cPath (or '' if not present).
So additional logic will be needed with the above code changes if one wants to selectively redirect certain products (or only in certain cases)... Kinda defeating the purpose of modifying the PHP code in the first place... And of course once additional PHP code is added (or existing files edited), added complexity is in play... The possibility (and risk) of multiple chained redirects increases... Troubleshooting "redirect" issues (if they occur) becomes more time consuming... Upgrading Zen Cart becomes slightly more time consuming...
I'd personally avoid using such redirects in the first place... But if the client is adamant about deleting products and using redirects... Make sure to update the code previously presented. At the minimum use zen_href_link() and $cPath... Ideally some additional logic could be added to call the home page (no "&cPath=" when no cPath is available). Time permitting, some code could also be added to make sure the redirect only occurs on a "deleted" product (not on product IDs which do not yet exist / have not yet been used).
NOTE 1: Disabling / deleting a category is a whole different beast. In most cases, I would avoid the need and simply change the content... But sometimes one may desire to make such a change (especially if inheriting a site with overly nested categories)... I'd think about a 301 redirect (using mod_rewrite) if there is another category with very similiar content... Otherwise I'd let the 404 page handle the situation...
NOTE 2: Not really on topic, but something I should probably mention... I'd recommend (with or without redirects) one create / supply a good 404 page for customers. Ideally a good 404 page has: easy to use navigation, a search box, content customized to the broken URL (pre-populated search results, a link to the containing category when known, etc), and possibly some form of humor.
NOTE 3: Remember SEO and Best Practices tend to change over time. Any advice or opinions on this (or any site) should always be taken with a grain of salt. Make sure you do your research (including A/B testing) to determine the most beneficial course of action for your specific store. And always keep a backup handy!
NOTE 4: The highlighted portion only applies to Ultimate URLs when "automatic redirects" are enabled and the 3rd party code does not call zen_href_link(). This will not apply if the 3rd party code is updated to correctly utilize zen_href_link().
Bookmarks