htaccess redirect rule
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

What would the htaccess rule(s) be for the following permanent rewrite scenarios:

http://mydomain.com/blog

forwards to

http://mydomain.com/articles

and

http://mydomain.com/blog/2012/12/18/this-is-the-slug/

forwards to

http://mydomain.com/articles/view/this-is-the-slug/

awarded to ochi

Crowdsource coding tasks.

2 Solutions

Winning solution

RewriteEngine On
RewriteBase / # optional based on your configuration

RewriteRule ^blog$ articles [L,R=301]
RewriteRule ^blog/(\d+){4}/(\d+){2}/(\d+){2}/(.*) articles/view/$4 [L,R=301]

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^blog$ articles [L,R=301]
RewriteRule ^blog/(\d+){4}/(\d){1,2}/(\d){1,2}/(.*) articles/view/$4 [L,R=301]

Do not forget about the Options +FollowSymLinks option.

I've also changed the regex to accept not only /blog/2012/12/18/this-is-the-slug/ but /blog/2012/5/2/this-is-the-slug/ (or at least it's suppossed to do so, I didn't tested it)

Edit:

Replacing ^blog/(\d+){4}/(\d){1,2}/(\d){1,2}/(.*) to ^blog/(\d){4}/(\d\d?)/(\d\d?)/(.*) will work as well

View Timeline