diff --git a/_layouts/guides.html b/_layouts/guides.html
index 7b301abf53..bb1846dc8e 100644
--- a/_layouts/guides.html
+++ b/_layouts/guides.html
@@ -8,7 +8,13 @@
{% assign docversion = 'latest' %}
{% endif %}
{% assign docversion_index = docversion | replace: '.', '-' %}
-{% assign page_filename = page.path | replace: '_guides/', '' %}
+{% comment %}
+'page.path' pattern is different depending on the version
+- "Main - SNAPSHOT" -> _versions/main/guides/*.adoc
+- "x.x.x - Latest" -> _guides/*.adoc
+=> to extract the page filename you need two different replacement tokens
+{% endcomment %}
+{% assign page_filename = page.path | replace: '_guides/', '' | replace: '_versions/main/guides/', '' %}
{% assign relations = site.data.versioned[docversion_index].index.relations %}
{% assign guide_url = page.url | replace_regex: '^/version/[^/]+(/.*)', '\1' %}