A broken link is a small problem that can quietly become a larger one. A reader follows an internal recommendation and reaches a 404 page. An illustration no longer loads. A documentation link points to an old URL, or a newly drafted article links to another draft that was never published.
For an Astro blog, these errors are particularly avoidable: most of the site is generated into static HTML at build time, so we can inspect the output before deploying it.
In this guide, you will learn how to find broken links in Astro with Lychee, automate checks with GitHub Actions, and distinguish actual broken URLs from temporary errors or anti-bot restrictions. We will also cover an important limitation: a successful build does not prove every URL works on the deployed website.
The examples assume a Git-based Astro site deployed to Cloudflare Pages. Adapt paths and package scripts to your own repository.
1. Why Broken Links Matter
Broken links interrupt a reader’s journey. They can make navigation confusing, prevent access to supporting evidence, and reduce the usefulness of older tutorials.
Typical causes include:
- A post slug changes after publication.
- A Decap CMS draft links to content that is not yet live.
- A Markdown image points to a filename that was renamed during upload.
- External documentation moves to a different location.
- A static asset is referenced with the wrong capitalization.
- The site’s routing or deployment configuration differs from the local preview.
Fixing these problems is good for users. It also supports site maintenance and crawlability, although a link-checking workflow does not guarantee higher Google rankings.
2. Choose the Right Kind of Link Check
There are three different things you may want to test:
| Check | What it answers | When to run |
|---|---|---|
| Source content check | Are Markdown links syntactically recognizable? | While editing |
| Built-site check | Do internal URLs and assets resolve in the generated site? | Before merging or deploying |
| Production check | Are deployed pages and external resources actually reachable? | After deployment and periodically |
These are related, but not interchangeable.
For example, a draft included in a preview build may not exist in a production build. A link can pass in preview and still return 404 on the published website.
Likewise, a file may exist in a repository but not be copied to the build output expected by your hosting configuration.
3. How the Astro Link-Checking Pipeline Works
Our recommended workflow is:
- An author changes Markdown content, images, or routes.
- GitHub Actions installs dependencies and builds Astro.
- Lychee checks local links in the generated HTML.
- A separate external-link check reports suspicious remote URLs.
- The author fixes confirmed issues and reruns CI.
- Cloudflare Pages deploys the approved build; the live URL receives a final spot check.

Figure 1: Link checking should run before deployment and be followed by production verification.
This gives you early feedback without assuming every third-party server will respond consistently to automated requests.
4. Prepare the Astro Project
From the repository root, install dependencies and generate a production build:
npm ci
npm run build
A typical Astro project places generated files in dist/, unless outDir has been customized in astro.config.*.
For a static blog you may see paths such as:
dist/
index.html
blog/
article-title/
index.html
images/
uploads/
illustration.webp
This directory structure matters because a browser URL like /blog/article-title/ may correspond to dist/blog/article-title/index.html on disk.
If your site uses server-rendered routes, middleware, or Pages Functions, an HTML-only scan cannot fully validate those runtime endpoints. You need separate integration or HTTP tests for them.
5. Install and Explore Lychee
Lychee is an open-source link checker that works with HTML, Markdown, and other text-based documents.
You can install it from its official releases or run it using the maintained GitHub Action. The GitHub Action is a convenient starting point because it avoids requiring every contributor to install a separate local binary.
For local experiments, first consult Lychee’s current installation instructions for your operating system. Then inspect the available options:
lychee --help
Useful capabilities include:
--root-dirfor resolving site-root-relative paths like/images/uploads/cover.webpagainst local build output.--index-filesfor matching directory links toindex.html.--offlinefor local-only checks without remote HTTP requests.--method head,getfor fallback when a remote server does not supportHEAD.--excludeand.lycheeignorefor known non-checkable URLs.
Options can evolve between releases; match the documented flags to the version selected by your CI workflow.
6. Check Generated Internal Links Before Deployment
For a static Astro site with trailing-slash URLs, you can start with a local check against the built HTML.
A Linux/macOS shell example:
lychee \
--offline \
--root-dir "$(pwd)/dist" \
--index-files index.html \
--exclude '^https?://' \
'dist/**/*.html'
This intentionally excludes HTTP(S) links so the job focuses on locally resolvable paths. For example, a link to /images/uploads/missing.webp should be checked against the generated dist/images/uploads/ directory.
Important limitation: Absolute links beginning with https://duonghoangnam.com/ are also excluded in this example. They require an additional check against the production domain or explicit URL normalization. This is not a complete verification of every internal link on the website.
Before relying on the command, confirm that Lychee scans the expected input files and that your Astro outDir, trailing slash conventions, and route behavior match the assumptions above.
A useful smoke test is to insert a deliberately invalid local link into a temporary test page, build, and confirm that the checker reports it. Remove the test link afterward.
7. Add Automated Checking with GitHub Actions
Create this file in your repository:
.github/workflows/check-links.yml
Then add a workflow similar to the following:
name: Check Astro links
on:
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
internal-links:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: npm
- name: Install dependencies
run: npm ci
- name: Build Astro
run: npm run build
- name: Check local links
uses: lycheeverse/lychee-action@v2
with:
args: >-
--offline
--root-dir "${{ github.workspace }}/dist"
--index-files index.html
--exclude '^https?://'
'dist/**/*.html'
fail: true
This job builds the site and then asks Lychee to verify local links in the output. A failure can be made a required status check before merging a pull request.
Production safety: Do not automatically deploy or publish content from the link-check job. Keep the job read-only; let your existing Cloudflare Pages deployment process remain separate.
The @v4 action references are examples of known major versions, not a claim that they are the newest available. For stricter supply-chain security, pin third-party actions to reviewed commit SHAs and update those pins deliberately.

Figure 2: Not every failed automated request means a destination has disappeared.
8. Check External Links Separately
Unlike local paths, external links require network requests. Some services return 403 Forbidden or 429 Too Many Requests when they detect automated checking. Others return 500 during a temporary outage.
An optional, report-only GitHub Actions step is:
- name: Report external link issues
uses: lycheeverse/lychee-action@v2
with:
args: >-
--method head,get
--timeout 15
--max-retries 2
'dist/**/*.html'
fail: false
This example scans URLs in generated HTML and may check both remote and local references. It is not a pure external-only scan; configure exclusions and --root-dir appropriately for your project, or isolate the remote URLs in a separate input list.
Because fail: false keeps the job from blocking the whole pipeline, someone must still review the report. Treat it as a starting point for diagnosis, not a list of links to delete automatically.
You may exclude authentication pages, private dashboards, or known anti-bot endpoints, but keep exclusions narrow and documented.
9. Diagnose 404, 403, 429, and Other Results
Use the HTTP status and the context of the link together:
| Result | Likely interpretation | Recommended action |
|---|---|---|
| 404 Not Found | Resource may have moved or been deleted | Open URL; correct slug or add a valid redirect |
| 410 Gone | Resource was intentionally removed | Replace or remove reference |
| 403 Forbidden | Access requires permission or blocks automation | Check in browser; do not assume missing |
| 429 Too Many Requests | Rate limit triggered | Retry less aggressively or exclude noisy endpoint |
| 5xx | Remote server problem | Recheck later; investigate persistent failures |
| Timeout | Network or server did not respond in time | Repeat carefully; inspect connectivity |
| Local missing asset | File absent from generated output | Check CMS upload path, case, and build settings |
Do not configure the checker to treat every 403, 429, or 500 as a success merely to make CI green. That can conceal actual problems.
10. Fix Common Broken Links in Astro
Case A: An internal blog slug is wrong
Suppose your content links to:
[Astro SEO Guide](/blog/astro-seo-old-url/)
But the published article’s route has changed. Confirm its canonical URL on the live site and update the source Markdown to the actual slug.
Avoid guessing a new slug based on the title: the original route may contain additional words, punctuation normalization, or a custom CMS slug field.
Case B: A WebP image does not load
Example:

Check whether the file exists under the expected public assets directory and is present in the built output. On case-sensitive hosting, Workflow-Architecture.webp and workflow-architecture.webp can be different files.
For images uploaded through Decap CMS, also verify that the CMS-generated filename matches the Markdown reference and that the published branch contains the asset.
Case C: A draft links to an unpublished page
A preview may include content that Cloudflare Pages does not publish on the live branch. Decide whether to publish the destination, remove the link until the destination goes live, or link to an already published article.
Do not make CI pass by automatically publishing incomplete drafts.
Case D: A third-party documentation URL changes
Search the vendor’s official documentation for the current page. Prefer an official replacement rather than an unrelated search result or an unofficial clone.
11. Create an Editorial Pre-Publish Checklist
Automation catches many mechanical problems, but editorial review remains necessary.
Before publishing a new article, verify:
- The URL slug matches the intended route.
- Internal links lead to published pages.
- All body images exist and use the exact uploaded filenames.
- Featured and body images are not accidentally duplicated.
- External documentation links still support the associated claims.
- Code samples do not include placeholder URLs presented as real endpoints.
- CI checks ran against the intended production build.
- The live page and images were opened after deployment.

Figure 3: Source review, CI checks, and production verification serve different purposes.
A broken-link checker cannot judge whether a link is relevant. A valid URL could lead to the wrong article, an outdated version of a manual, or a page that contradicts the claim beside it.
12. Watch for Astro and Cloudflare Pages Edge Cases
Trailing slashes
Astro routing settings and your hosting configuration determine whether /article/, /article, and /article/index.html behave consistently. The build-output directory may differ from the browser-facing path.
Test the actual deployed route rather than assuming every static host handles redirects identically.
Redirects
Redirects may be implemented by Cloudflare or another edge layer and not be present as HTML files inside dist/.
An offline check cannot verify redirects that exist only in the production configuration. Include those URLs in a live HTTP check.
On-demand routes and Pages Functions
Routes handled dynamically do not necessarily produce local HTML files. Validate these with HTTP or integration tests suited to their expected methods and authentication.
Absolute production URLs
A source file may contain https://duonghoangnam.com/blog/... instead of a root-relative URL. The offline command in section 6 deliberately skips it, so add a separate production-domain check if your editorial workflow frequently uses absolute URLs.
13. Monitor Links After Deployment
A useful maintenance plan has two layers:
On pull requests: Run Astro build and local link validation. Require fixes for confirmed broken internal paths.
Periodically: Check selected live article URLs and external references, perhaps weekly or monthly depending on how often the website changes. Record repeated failures and revisit them rather than treating every transient response as an emergency.
For a growing content library, track:
- Number of broken internal links per release.
- Missing image references.
- External links requiring manual review.
- Time taken to correct confirmed issues.
- Repeated link failures by page or topic.
These are operational quality metrics, not direct SEO ranking factors.
14. Common Mistakes
Scanning Markdown but never checking the production build. Source content can be valid while generated routes or asset paths are missing.
Assuming a green CI run proves the deployed site works. A successful test covers only its configured environment and inputs.
Making all remote link failures blocking. Rate limits and anti-bot systems can create flaky CI unrelated to your content changes.
Excluding too much. Broad ignore rules can hide genuine broken links.
Automatically replacing URL destinations. A replacement URL may be reachable but contextually incorrect.
Checking draft pages as though they were published. Always use the intended production build or verify live routes explicitly.
15. Frequently Asked Questions
Can GitHub Actions check Astro links for free?
You can run link checks in GitHub Actions within your repository’s applicable plan limits. Availability and usage quotas depend on your repository visibility, account, and GitHub billing terms.
Does Lychee check WebP images?
It can check file references embedded in HTML or Markdown. A local missing image path can be detected when correctly resolved against the build directory. It does not evaluate whether the image visually matches the article.
Will broken links always cause SEO penalties?
Not necessarily. Broken links can harm usability and site maintenance, but you should not interpret every 404 as a guaranteed ranking penalty. Fix URLs that are meant to work, particularly navigational and editorial references.
Why does a valid URL return 403 in CI?
Some services require authentication or restrict automated requests. Open the URL manually and check the site’s access policy before labeling it broken.
Should I check URLs before or after Cloudflare Pages deploys?
Both. Pre-deployment tests catch missing generated routes and assets early; post-deployment checks catch problems caused by hosting, redirects, custom domains, or runtime behavior.
Can I use this with Decap CMS?
Yes. Since published Decap CMS content becomes repository content in a Git-based workflow, the generated Astro site can be scanned after the corresponding source changes are built. Draft and editorial-workflow states still need to be respected.
16. Final Thoughts
A healthy content site requires more than publishing new articles. It needs a repeatable way to catch mistakes as URLs, images, and supporting references evolve.
For Astro, a practical solution is to build the site, inspect local links with Lychee, review remote-link warnings separately, and verify the deployed result.
The biggest improvement is not the choice of a particular GitHub Action. It is adopting a simple rule: every important link should be checked in the environment where readers will actually use it.
Continue Reading
- Astro SEO Guide 2026: 12 Essential Steps to Optimize Your Website for Google — Build a broader technical SEO foundation.
- Decap CMS Images Not Showing? How to Fix Draft 404s and Publishing Errors — Troubleshoot missing images and publishing issues.
- How to Add Fast Full-Text Search to Astro with Pagefind (2026 Guide) — Improve article discovery across your site.
Official Technical References
- Astro: Deploy your Astro site
- Lychee: Official repository and command-line documentation
- Lychee GitHub Action
- GitHub: Setup Node.js in Actions
Technical disclosure: The commands and CI workflow are reference examples based on public documentation. They have not been run against the private source repository or verified as a working CI job for DuongHoangNam.com. Test with your project’s actual build output, routing, and Cloudflare Pages configuration before making the job a required check.






