Web Development

I have recently moved my development platform from CakePHP to Ruby on Rails after 2 years of maintenance. The recent version of CakePHP was so extreme that I thought of creating a whole new application. It was also an opportunity for me to develop new features. The recent change has prompted me to redirect each URLs from a date format to a more natural text only URL.

It’s quite easy to redirect but the number of URLs has made it difficult. Here are a few redirections:

location /2012/11/13/exploring_microframeworks{
  rewrite ^ http://$server_name/posts/exploring_microframeworks permanent;
}
location /2013/03/14/rewriting_foodscaper{
  rewrite ^ http://$server_name/posts/rewriting_foodscaper permanent;
}
location /2013/03/31/handy_shortcuts_using_rubymine{
  rewrite ^ http://$server_name/posts/handy_shortcuts_using_rubymine permanent;
}
location /2013/05/24/back_to_php{
  rewrite ^ http://$server_name/posts/back_to_php permanent;
}
location /2013/05/30/logging_in_as_another_user_in_cakephp{
  rewrite ^ http://$server_name/posts/logging_in_as_another_user_in_cakephp permanent;
}

Working with an awesome editor and Ruby has made it easier to generate about 200 of them.

Post.all.each {|post| puts "location /#{post.created_at.strftime('%Y')}/#{post.created_at.strftime('%m')}/#{post.created_at.strftime('%e').delete('')}/#{post.slug}{rewrite ^ http://$server_name/posts/#{post.slug} permanent;}"}

Thanks for reading!