如何在Jekyll中让站点根目录引用“_pages”并调整访问URL?
The issue you’re hitting is that Jekyll uses a file’s directory path in its generated URL by default. To adjust this so your pages show up at /some-page/ or /pages/some-page/, you can override the permalink setting in your _config.yml defaults. Here are two straightforward solutions:
1. Make Pages Accessible at the Root (e.g., /some-page/)
Add a permalink value to your _pages scope in _config.yml that strips out the _pages prefix. You can choose between using the page’s filename or its front matter title:
Using the Filename (Recommended)
This uses the page’s filename (without the .md extension) as the URL path. For example, some-page.md becomes /some-page/:
# Defaults defaults: # _pages - scope: path: "_pages" type: "pages" values: layout: "single" read_time: true permalink: "/:basename/"
Using the Page Title
If you prefer to use the title field from each page’s YAML front matter (e.g., title: "Some Page" becomes /some-page/), use this instead:
permalink: "/:title/"
Note: Ensure every page in _pages has a title in its front matter for this to work reliably.
2. Make Pages Accessible Under /pages/ (e.g., /pages/some-page/)
Adjust the permalink to include a pages prefix instead of the _pages directory name:
# Defaults defaults: # _pages - scope: path: "_pages" type: "pages" values: layout: "single" read_time: true permalink: "/pages/:basename/"
Final Steps
After updating your _config.yml:
- Stop your local Jekyll server (if it’s running)
- Rebuild the site with
jekyll buildor restart the server withjekyll serve - Test the new URLs to confirm they load your pages correctly
This approach keeps your pages organized in the _pages directory while giving you full control over their public URL structure.
内容的提问来源于stack exchange,提问作者v.karbovnichy

