Rewrite image url for SEO


I’m using Grav 1.7.10 and I would like the images used in my websites to have the shortest possible URL, something like “
A similar topic has already been posted in 2017 here SEO-friendly image URLs but I didn’t find an answer to my questions in it…

Depending on how I display my images, their URL can be of two types :

  1.” when the original image is used,
  2.” when, for example, I modify the original image using image.resize().html()

In both case the URLs are two long and I’m searching for a way to shorten them. I especially don’t understand why, in case 1., the “user/pages/06.ttttt/” appears in the URL… I would expect the URL to be “”. Is it possible to achieve this ?

1 Like

@jordan, Would you mind sharing in what way the SEO of an image is seriously impacted by its URL?

As far as I know, it is the least important aspect after alt, title, context, etc…

I would expect the URL to be “”. Is it possible to achieve this ?

An image is accessed by its file path relative to the root of the site. Since Grav is not involved in fetching an image, a slug will not be translated to an existing path.

It seems to be a rule: a logical structure is important for SEO. So, I think /user/truc/much/m/y/p/i/c/t/u/r/e/mypicture.jpeg is worse than /picture/mypicture.jpeg

Maybe for pictures it’s less important, but I don’t know why…

@robin, Could you provide some references to back this up?

  • Create good URL structure for your images: Google uses the URL path as well as the file name to help it understand your images. Consider organizing your image content so that URLs are constructed logically.
1 Like

So having a “logical URL structure” for images may be less important than the context or having correct alt and title, but it seems to be one of the good practices recommended by Google.

This being said, would someone have an idea of how to rewrite Grav images URLs ?

1 Like

I guess not without a plugin. I was thinking for a while now for some files plugin, that would change URLs so that files could be forced to download instead of opening in browser, but it’s just an idea that might be a step to image URL rewrite.

And TBH I really hate cached images folder structure now. I believe it’s supposed to spread images so there wouldn’t be too many on a single folder by taking 4 first letters of image file name and splitting to folders, but my all images are from camera and first 4-5 symbols are always the same, so this cached folders structure makes no sense at all in my case.

1 Like

Since we’re talking about image handling, I’m also quite concerned by the fact that the current mechanism of adding effects to or simply resizing images produces non-optimized images in terms of size. I keep getting “suggestions” from Google that I should optimize the images, because Grav makes them too large even though the original images were optimized.
:slight_smile: I know this should go in another thread, it’s just a comment.

If you want your concern to get the attention of the Grav developers I suggest you create an issue in the main Grav repository on GitHub.

Thanks for the tip. They’re well aware of that issue. Unfortunately, it depends on some external library and changing that dependence won’t happen soon, as far as I remember from another answer on GitHub.