Reputation: 68
Thank you for taking the time to read my question!
I currently have a large ecommerce store with over 4000+ URLs. We are in the process of finishing up the development on the brand new, re-platformed version of the website, and unfortunately that has led to a change in the URL format for all of our products.
I am not very familiar with the syntax to use to create the RewriteRule to handle the scenario below. If you can help me out it would be greatly appreciated!
Scenerio:
Original URL: http://www.example.com/p-22-some-product-seo-name.aspx
This URL needs to be converted to...
New URL: http://www.example.com/some-product-seo-name
Notice, that the first part of the original URL the (p-xx-
) needs to be removed. Where xx
is the product id that was used in the old URL. That ID is not always 2 digits and can be 1-8 digits in length depending on the product.
Also, the .aspx
needs to be removed from the end of the url, leaving just the hyphenated SEO name.
I have tried the following (and many variations of it) but to no avail!
RewriteRule ^p-([^-]*)-([^-]*)\.aspx$ /$2 [R=301, NC]
Upvotes: 0
Views: 30
Reputation: 9007
Your expression should be changed to the following:
^p-([\d]{1,8})-([\w-]+)\.aspx$
Where the first capture allows for between one and eight digits, and the second capture allows for alpha-numeric characters, underscores, and hyphens.
Upvotes: 1