1

I'm just moving my blog over to Ghost and all was ok except for around 50% of my blog posts are broken due to the date not being zero padded i.e.

old site format: http://www.example.com/blog/index.cfm/2013/8/9/my-slug

new site format: http://www.example.com/2013/08/09/my-slug

Removing the /blog/index.cfm was easy via

location /blog/index.cfm {
    rewrite ^/blog/index.cfm(/.*)$ $1 last;
}

But cannot think of a way to zero pad dates (and there is around 700 posts).

Andy Jarrett
  • 863
  • 2
  • 9
  • 26

1 Answers1

3

Put several rewrites.

location /blog/index.cfm {
    # 2013/1/1
    rewrite ^/blog/index.cfm(/\d+)/(\d)/(\d)(/.*)?$ $1/0$2/0$3$4 last;
    # 2013/1/11
    rewrite ^/blog/index.cfm(/\d+)/(\d)/(\d\d)(/.*)?$ $1/0$2/$3$4 last;
    # 2013/11/1
    rewrite ^/blog/index.cfm(/\d+)/(\d\d)/(\d)(/.*)?$ $1/$2/0$3$4 last;
    # all other
    rewrite ^/blog/index.cfm(/.*)$ $1 last;
}
Alexey Ten
  • 13,794
  • 6
  • 44
  • 54
  • I have slightlly difrent needs old site format: http://www.example.com/blog/index.cfm/2013/03/my-slug new site format: http://www.example.com/my-slug How to make redirect via 301? Can you help? – aholbreich Oct 06 '15 at 17:47
  • @shuron, it's really easy, but feel free to ask you own question – Alexey Ten Oct 06 '15 at 18:01
  • @AlexeyTen done http://stackoverflow.com/questions/32977170/nginx-redirect-url-to-new-format – aholbreich Oct 06 '15 at 18:35