Dealing with conflicts between “/blog.html” and “/blog/index.html” in ablog#
When I was building a blog site using ablog, both /blog.html and /blog/index.html were generated in the output after the build, and there were situations where I was confused about the handling of URLs and link behavior. This article summarizes the causes and solutions.
Problem occurrence situation#
Using Sphinx + ablog with the following configuration:
Create
blog/index.rstand define your own blog top pageconf.pysetting isblog_path=blog(default value)
Building in this state will generate the following two HTML files:
/blog.html(all article list page automatically generated by ablog)/blog/index.html(Build result ofblog/index.rstthat I created)
As a result, the following collision occurs:
toctreelink destination changes depending on whether it is/blogor/blog/index.htmlWhen accessing
/blogon Netlify,/blog.htmltakes precedence
Cause and specifications#
By default, ablog is set to blog_path = "blog", and in this case, /blog.html is automatically generated as a page listing all articles. On the other hand, if you create blog/index.rst, it becomes /blog/index.html.
In other words, the problem is that /blog.html and /blog/index.html exist separately at the same time.
How to deal with it#
To keep your blog/index.rst and avoid conflicting with ablog’s output, it is effective to change the value of blog_path in conf.py.
For example, set as below:
blog_path = "blog/posts"
This results in:
All article list page generated by ablog →
/blog/posts.htmlHomemade
blog/index.rst→/blog/index.html
This separates roles and avoids conflicts and confusion.
Note: URL priority order in Netlify#
In Netlify, when accessing /blog, /blog.html is displayed with priority (static file-based rule). Therefore, it is possible to use netlify’s redirect settings, but it is smarter to correct the folder structure:
/blog /blog/index.html 200
summary#
The automatic output destination for ablog is determined by the
blog_pathsetting.If you create
blog/index.rst, it is safe to use a separateblog_path.Also note that
/blogis treated as/blog.htmlin static output.
Article information
- Post date:
2025-04-02
- author:
Mr. Takagi