Testing Sites Not Served from Root with --base
What Is The Base URL?
The --base
parameter in lychee lets you check links for sites that aren’t
served from the root domain. This is useful when your site lives in a
subdirectory, like example.com/docs/
.
Do You Need To Set A Base URL?
Most of the time, you don’t! Skip --base
if:
- Your site runs at a root domain (like
example.com
) - You’re only checking absolute URLs
- Your links should resolve relative to their files
You need --base
when your site lives in a subdirectory.
Let’s look at an example:
Say this page will be deployed to example.com/docs/guide.html
. Those relative links should resolve to:
example.com/docs/getting-started.html
example.com/about.html
To check if these links are valid, tell lychee where the site will be hosted:
How Does It Work?
When you set --base
, lychee will:
- Find all links in your HTML files
- Convert relative links to full URLs
- Check if the referenced files exist in your project
Here’s what happens to different types of links:
Common Use Cases
Documentation Sites
Running your docs locally? Tell lychee to check against your dev server:
Want to verify links before deploying? lychee can check if files exist in your project:
GitHub Pages
If your site will be on GitHub Pages:
Blogging Platforms
Using WordPress, Ghost, or Jekyll with a blog at example.com/blog/
? Here’s how to check those links:
Local Development
You can use file://
URLs to check files without running a server:
This is helpful when you want to verify links exist on your filesystem.
Important Details
Let me explain the technical necessity of the trailing slash:
Add A Trailing Slash If It’s A Directory
When in doubt about whether to include the trailing slash, include it. It’s almost always what you want when working with static sites and documentation.
The trailing slash is crucial because it tells lychee whether /docs
is a file or a directory. This follows standard URL resolution rules:
-
https://example.com/docs/
(with slash) means “docs” is a directory./guide.html
resolves to/docs/guide.html
../about.html
resolves to/about.html
-
https://example.com/docs
(no slash) means “docs” could be a file./guide.html
resolves to/guide.html
(goes up one level!)../about.html
resolves to/about.html
lychee can’t automatically add the slash because both forms are valid - they just mean different things. For example, https://example.com/docs
might be a single page, while https://example.com/docs/
is its directory version. This distinction is part of how URLs work on the web.
—base vs —root-dir
These solve different problems:
-
--base
is for URLs (likehttps://example.com/docs/
)- Use it when you care about your site’s final URL structure
- Helps validate relative links
-
--root-dir
is for file paths (like./public/
)- Use it to find files on your computer
- Helps validate absolute paths
You can use both together:
Troubleshooting
If links aren’t being checked correctly:
- Verify your base URL has a trailing slash
- For local development, ensure your server is running
- Use
--verbose
to see how lychee resolves links