Question

I've started the process of moving my blog to Octopress, but unfortunately, a limitation of Jekyll doesn't allow me to use abbreviated month names for my permalinks. Therefore I'm looking to just get rid of the month and day bits altogether.

I'ved read in this article that you can use rack-rewrite to take care of the redirection, since I am using Heroku to host this.

So how would I turn:

This: example.com/journal/2012/jan/03/post-of-the-day/
Into this: example.com/journal/2012/post-of-the-day/


Extra points: If I had another rule that redirected /blog/ to /journal/, would that rule still adhere to the above one as well? So from:

This: example.com/blog/2012/jan/03/post-of-the-day/
To this: example.com/journal/2012/jan/03/post-of-the-day/
And finally to: example.com/journal/2012/post-of-the-day/

Thanks for the assistance in advance. :)

Was it helpful?

Solution

You want to be as specific as possible, so you don't accidentally rewrite something else that would fail when it hits the new URL structure. Also note that I don't know rack-rewrite, so I'm following redroot89's lead on that point.

r301 %r{^\/(:blog|journal)\/([0-9]{4})\/[a-z]{3}\/[0-9]{2}\/(.*)\/$}, '/journal/$1/$2/

This captures just the year and slug, but finds the rest by more specific patterns. And by including the (:blog|journal) you can redirect both in one shot, without having to chain two redirects together.

OTHER TIPS

My first thought would be to catch every chunk between the slashes then just display the ones you want.

So something like this would work:

// given example.com/blog/2012/jan/03/post-of-the-day/

r301 %r{\/blog\/(.*)\/(.*)\/(.*)\/(.*)\/$}, '/journal/$1/$4/'

Here's a link to Rubular to show what I mean http://rubular.com/r/La6rjrE5Hw

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top