Skip to content

Jekyll Relative URL Error Fix

DodaTech Updated 2026-06-24 1 min read

In this tutorial, you'll learn about Jekyll Relative URL Error Fix. We cover key concepts, practical examples, and best practices.

The Problem

Broken CSS and links when deploying to a subpath like https://user.github.io/repo/.

<link rel="stylesheet" href="/css/main.css">

This resolves to https://user.github.io/css/main.css instead of https://user.github.io/repo/css/main.css.

Wrong

<link rel="stylesheet" href="/css/main.css">

Output: 404 Not Found — /css/main.css

Absolute paths break when the site is served from a subdirectory.

Use relative_url filter:

<link rel="stylesheet" href="{{ '/css/main.css' | relative_url }}">

Or prepend site.baseurl:

<link rel="stylesheet" href="{{ site.baseurl }}/css/main.css">

Set baseurl in _config.yml:

baseurl: "/repo"

Output: <link rel="stylesheet" href="/repo/css/main.css">

Prevention

  • Use relative_url filter for all asset paths
  • Set baseurl in config for subpath deployment
  • Test locally with JEKYLL_ENV=production bundle exec jekyll serve

Common Mistakes with relative url

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

These mistakes appear frequently in real-world JEKYLL code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between `relative_url` and `absolute_url` in Jekyll?

relative_url prepends the baseurl. absolute_url prepends both baseurl and url (the full domain). Use relative_url for assets and absolute_url for canonical links.

Why do my CSS files work locally but break on GitHub Pages?

GitHub Pages serves your site from username.github.io/repo/. Your CSS paths must include the repository name. Use relative_url to automatically handle this.

How do I configure baseurl for local development?

Set baseurl: "" in a local override config file _config_dev.yml and run bundle exec jekyll serve --config _config.yml,_config_dev.yml.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro