diff --git a/sphinx_rtd_theme/layout.html b/sphinx_rtd_theme/layout.html
index 9b00d0320..af8d59057 100644
--- a/sphinx_rtd_theme/layout.html
+++ b/sphinx_rtd_theme/layout.html
@@ -65,7 +65,10 @@
Workaround for: https://github.com/sphinx-doc/sphinx/issues/9730
Once a fix is released in Sphinx, put an upper bound on the Sphinx version for the workaround
-#}
- {%- if builder == 'dirhtml' and pageurl.endswith('.html') %}
+ {%- if builder == 'dirhtml' and pageurl.endswith('index.html') %}
+ {#- This expression trims away index.html entirely #}
+
+ {%- elif builder == 'dirhtml' and pageurl.endswith('.html') %}
{#- This expression trims away .html and adds a / #}
{%- else %}