views:

210

answers:

2

I need to redirect from path

 /articles/20090425-swine-flu-kills.html

to

 /2009/04/swine-flu-kills.html

In the original path, the digits after articles are the dates in yyyymmdd format. This to convert to "/yyyy/mm/" in the new path.

I suppose need some regex but I am not sure how. Would appreciate help. Thanks

+1  A: 

Try this:

RewriteRule ^articles/(\d{4})(\d\d)\d\d-(.*)$ /$1/$2/$3

This matches:

  • ^articles/: Strings starting with "articles/"
  • (\d{4}): 4 digits into $1 (the year)
  • (\d\d): 2 digits into $2 (the month)
  • \d\d-: 2 digits & dash (edit: missed the leading dash)
  • (.*)$: The rest of the URL into $3
Greg
+1  A: 
RewriteRule ^articles/(\d{4})(\d\d)\d\d\-(.+)$ /$1/$2/$3

Would be a better solution.

BYK
Thanks! I will try out both. Only one character difference, to me :-)
Gaius Parx