I have a bunch of products listed at
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 these to be redirected to
https://www.example.com/products.php?p=1234567890
https://www.example.com/products.php?p=7654321
https://www.example.com/products.php?p=93939393
respectively. Is there an htaccess rule to do string operations on a matched 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 ID is found after the last "/" and just before the first "-". Another regular expression based rule that would work would be:
\/(\d*?)\-
Any thoughts as to how to accomplish this inside an Apache htaccess file?
https://www.example.com/products.php?p=1234567890in browser?https://www.example.com/all/products/foldername/1234567890-ProductDescriptionA-456.htmlI wanthttps://www.example.com/products.php?p=1234567890to be returned. I don't care about any of the content except SOMENUMBERS in:...../foldername/SOMENUMBERS-otherstuff.html