I have a bunch of products listed in
https://www.example.com/all/products/foldername/1234567890-ProductDescriptionA-456.html
https://www.example.com/all/products/foldername/7654321-SomeOtherDesc-B123.html
https://www.example.com/all/products/foldername/93939393-anotherthing-F93939393.html
and I want them to be redirected to
https:
https:
https:
respectively. Is there an htaccess rule for performing string operations on an agreed parameter? For example, if I had to convert my URL using Python, it would look like this:
def make_new_url(old_url):
product_id = old_url.split('/')[-1].split('-')[0]
new_url = 'https://www.example.com/products.php?p=%s' % product_id
return new_url
In the old URLs, the product identifier is after the last "/" and immediately before the first "-". Another rule based on regex that will work:
\/(\d*?)\-
Any thoughts on how to accomplish this in an Apache htaccess file?
source
share