Redirect for images adding trailing slash

Just migrated a blog to Ghost. I migrated the /images/ directory of the old blog following the directions, as part of an import zip. But now the images are located at /content/images/ … which breaks all the images, of course. So I tried the following redirect:

  {
    "from": "^/images/(.+)" ,
    "to":  "https://www.domain.com/content/images/$1",
    "permanent": true
  },

…both with relative and absolute URLs for the “to” – but Ghost is adding a trailing slash at the end of the image file extension, which results in 404 errors.

but Ghost is adding a trailing slash at the end of the image file extension, which results in 404 errors.

Ghost only does that after it already got a 404 trying to load the file without the trailing slash. So the logic is

  • try image
  • get a 404
  • add a slash and try that
  • also 404
  • return

Thanks.

I did figure out that a side-effect of this is that the regexp $1 capture included the trailing slash, even though the original request path did not have one. Now I just need to figure out a regexp that captures a path like /images/blog/podcast.gif/ such that the $1 capture includes slashes in the directories but excludes the final trailing slash. Need to polish up my regular expression skills for that one. :wink: In the meantime, I create a few separate rules that match exact image paths…