You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Jekyll中让站点根目录引用“_pages”并调整访问URL?

Fixing Jekyll Page URLs for the _pages Directory

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:

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 build or restart the server with jekyll 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:21:32