While creating our automotive eCommerce store, we named a few products with Forward Slashes/Virgules in the name (“/”) for example: VOLKSWAGEN GOLF/GTI. The eCommerce engine rewrites the URL for this product to be GOLF%7B47%7DGTI. We decided to go ahead and reword all of our products to use the world “AND” and instead of a forward slash/virgule.
We have a ton of links out there on the web and I always use mod_rewrite to ensure that these links still work after we change the naming convention for products. However, this one has got me stumped! Here is what I’m trying to do:
OLD URL: http://mystore.com/products/MK4-GOLF%7B47%7DGTI-KONI-STRUTS.html
NEW URL: http://mystore.com/products/MK4-GOLF-AND-GTI-KONI-STRUTS.html
The “MK4” part of the URL could be any of Mk1, Mk2, Mk3, Mk4, Mk5 or Mk6 and we also offer a variety of struts for each generation of the Golf/GTI. Therefore, I needed to write a rule that would replace Golf/GTI with GOLF-AND-GTI in the URL and carry over anything before or after the target string.
My current (incorrect) RewriteRule looks like this:
RewriteRule ^products/(.*)-GOLF%7B47%7DGTI-(.*) http://www.mystore.com/products/$1-GOLF-AND-GTI-$2 [B,R,L]
I’ve been pulling my hair out over this for the last couple hours and just can’t seem to get a working rule in place. Any assistance would be greatly appreciated!
Thank you very much for your time!
As
%7B47%7Ddecodes to{47}you can rewrite the URL as follows:Also as your intention is to replace the old URLs with the new ones, you should use a 301 redirect instead of the default 302. This is the recommended way of handling permanent URL changes from SEO standpoint.