0

The way that Oscommerce SEO Friendly URLs work, is that they are generated from a product or category title followed by a p for product and c for category, then the product or category ID. For categories, each parent directory ID is also used. for example:

https://example.com/jeep-pinion-gears-c-284_845.html

over the course of many years, products and categories get edited and moved therefore changing the URL. However, all the old URL's still resolved because pages are served strictly based off of the last part of the URL. It looks for the c or p and the ID's. SEO is still able to be maintained. For Example:

https://example.com/jeep-pinion-gears-c-284_845.html
https://example.com/jeep-pinion-gears-and-accessories-c-284_845.html
https://example.com/jeep-pinion-gears-c-284_1234_845.html
https://example.com/ring-pinion-gears-c-845.html

Would all load the same content.

I've recently changed over to OpenCart where I used the latest URL for each product and category from the OsCommerce store. However, all the of Old Oscommerce URL's don't work.

I was originally writing some regex redirects to match the ID's but I'm running into redirect loop issues.

Does anyone any any ideas on a different approach?

wp78de
  • 18,207
  • 7
  • 43
  • 71
Steven Lutz
  • 467
  • 1
  • 6
  • 16
  • I suppose I can use a rewrite condition for each currently used URL to skip the rewrite rules if any of the conditions match. – Steven Lutz May 26 '18 at 01:20
  • I moved away from it which is why I'm having g this issue – Steven Lutz May 26 '18 at 02:41
  • 845 is the ID of this product? – wp78de May 26 '18 at 02:44
  • Yes but in this case it's a category – Steven Lutz May 26 '18 at 02:45
  • If there is no transformation rule that allows deducing the OpenCart URL from the OsCommerce slug you are pretty much lost. – wp78de May 26 '18 at 04:11
  • What if I so something like: rewritecond !(valid url) rewritecond !(valid url) rewritecond !(valid url) rewritecond !(valid url) rewriterule (regex matching -c-.*845.html) (valid 845 URL) [301] The rewrite condition should keep out the loops, the drawback is that I'll need to generate rule for every valid URL on the new site. – Steven Lutz May 26 '18 at 04:13
  • Since you have obviously more than 5 products and categories, this won't fly. – wp78de May 26 '18 at 05:03
  • Too slow? I can write a script to generate the rules. – Steven Lutz May 26 '18 at 05:04
  • I don't know. Depending on your context. But sounds like a bad idea. Maybe I am wrong. – wp78de May 26 '18 at 05:07
  • I agree it's big and bulky but I feel like I'm out of options. – Steven Lutz May 26 '18 at 05:08
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/171813/discussion-between-wp78de-and-steven-lutz). – wp78de May 26 '18 at 05:28
  • You need to hook into the seo url class (depends on version), parse the url being called and extract the relevant parts, then query the database to find out where it should be pointing. it would make things easier if you created a special table to map the old category/product_id to the new ones. either way it's a bit beyond the scope of an answer here. if you don't manage your own solution based on what I've suggested here feel freed to email me – But those new buttons though.. May 27 '18 at 04:00

1 Answers1

0

If there is a way to derive the new OpenCart URL from your OsCommerce SEO URLs

RewriteCond %{REQUEST_URI} !^/.*?-[cp]-\d+\.html$
RewriteCond %{REQUEST_URI} ^/(.*?)-([cp])-[\d_]*?(\d+)\.html$  [NC]
RewriteRule (.*) https://new.example.com/%2-%3.php [R=301,L]

The important part here is the stop not rule to prevent looping redirects.

put it below others rewrites, removing a trailing slash or the www-subdomain, or http to https rewriting.

If three is no "simple relationship" between the two URLs you are out of luck and have to write a redirect for each of them. You should be able to generate the rules using the SEO URLs stored in the DB.

Redirect 301 /old-page.html http://www.example.com/new-page.html

Maybe a PHP redirect could be helpful too?

header("Location: http://www.example.com/new-page.html", true, 301);
exit();

wp78de
  • 18,207
  • 7
  • 43
  • 71
  • The problem with this is that we don't know the text used (group 1) for it to match the opencart URL – Steven Lutz May 26 '18 at 03:20
  • The only way I can think of a solution is to match it with the opencart URL based on the c/p letter and ID and build a rewrite rule for each product and category. – Steven Lutz May 26 '18 at 03:23