Erich
Erich

Reputation: 2529

htaccess rewrite regex rule - insert dash and period in query string

I can't seem to figure out this specific regex htaccess rewrite, and could use some assistance. I'm trying to go from this:

mysite.com/product/13202102/any-random-product-name

and rewrite to this url:

mysite.com/product.php?id=13-2021.02

Note that the id will always have exactly 8 numbers, and will always require a dash (-) after the first 2 digits, and a period (.) before the last 2 digits. The tailing string is irrelevant, but I'd like the url to work with or without a trailing slash (/).

Upvotes: 2

Views: 651

Answers (1)

Jon Lin
Jon Lin

Reputation: 143966

Try:

RewriteRule ^/?product/([0-9]{2})([0-9]{4})([0-9]{2})/? /product.php?id=$1-$2.$3 [L]

Upvotes: 1

Related Questions