Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

SEO-friendly image URLs

Started by Muut Archive 10 years ago · 3 replies · 904 views
10 years ago

Hi @all!
Is there a way in Grav to make the image URLs more SEO-friendly?
Currently the generated URLs look somewhat like "src="/grav/images/c/1/e/d/b/c1edbe4be099530736c1e9ec39be7f52ef941a54- mock1x.png"

Ideally the img would be in the same directory, as the containing webpage (e.g. "/products/mock1x.png"); and also would not have any hash in the URL.

Thanks a lot for any suggestions!

👍 1
10 years ago

If you were to not cache them, but access them directly, they would appear as you expect.

10 years ago

Images are only cached when necessary, that is, when an action is applied to it by Grav. For example, with a file named unsplash_1.jpg in the user/pages/01.home/-folder:

user/themes/antimatter/default.html.twig

TWIG
{{ page.media['unsplash_1.jpg'].display('thumbnail').sepia().html() }}
{{ page.content }}

user/pages/01.home/default.md

MARKDOWN
...
# Grav is Running!
## You have installed **Grav** successfully

![Unsplash](unsplash_1.jpg)

Congratulations!
...

In the first line of code in the template, we are making the image sepia-toned. This is done dynamically by Grav, so it must be cached to retain it's changed appearance, and results in a path like:

TXT
http://temp.dev/images/1/b/5/1/a/1b51a1da4b76fc16dfc4c83f31ef3252abc35a05-unsplash1.jpeg

However, in the page's content, we are accessing the image directly (which we could also do in a template, by not adding any effects) and thus there is no reason for Grav to cache it. This results in a regular path:

TXT
http://temp.dev/user/pages/01.home/unsplash_1.jpg

So if you want to ensure SEO-friendly URLs, you'd need to do the processing yourself outside of Grav. I could imagine a system wherein the cache generates differently named URLs, exactly replicating paths from the user/pages/ structure, but it would potentially have to account for a variety of different configurations, which is why the current cache-mechanism is rather more fail-safe.

👍 1

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 2008 9 years ago
Archive · by Muut Archive, 9 years ago
2 1349 9 years ago
Archive · by Muut Archive, 9 years ago
2 4563 9 years ago
Archive · by Muut Archive, 9 years ago
1 3413 9 years ago
Archive · by Muut Archive, 9 years ago
3 1502 9 years ago