🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Routing••By Komal Nakrani

Fix: Unsupported or Malformed URL in Astro Redirects

Fix Astro's 'Unsupported or malformed URL' error: an external redirect in astro.config.mjs must start with lowercase http:// or https://. Common causes and fixes.

#Astro#Errors#Redirects#Routing

Astro throws “Unsupported or malformed URL” when a destination in the redirects option of astro.config.mjs looks like a full URL but doesn’t start with http:// or https://. Astro only supports external redirects to web URLs, so destinations like mailto:[email protected], ftp://files.example.com or HTTPS://example.com in capitals fail when the config loads. Change the destination to a lowercase https:// URL or a root-relative path.

Key Takeaways

  • The check runs on config redirects when Astro builds its route list, so it fails astro dev and astro build alike.
  • A destination that parses as a URL must match http:// or https://, and the match is case-sensitive.
  • mailto: and tel: links can’t be config redirects; link to them from a page instead.
  • host:port/path without a scheme is parsed as a URL with a strange scheme and fails too.

The exact error

Unsupported or malformed URL.

The destination URL in the external redirect from "/email" to "mailto:[email protected]" is unsupported.

Hint: An external redirect must start with http or https, and must be a valid URL.

The message names both sides of the redirect, so you can find the entry quickly.

What causes it

For each redirect, Astro checks whether the destination can be parsed as an absolute URL. If it can, the destination has to start with http:// or https://. Anything else that parses stops the build:

// astro.config.mjs  (broken)
import { defineConfig } from 'astro/config';

export default defineConfig({
  redirects: {
    '/email': 'mailto:[email protected]',      // mailto: scheme
    '/files': 'ftp://files.example.com/',      // ftp: scheme
    '/shop': 'HTTPS://shop.example.com/',      // uppercase scheme
    '/staging': 'localhost:4321/preview',      // parsed as scheme "localhost:"
  },
});

The last two are easy to miss. Browsers accept HTTPS://, but Astro’s check is a case-sensitive pattern. And localhost:4321/preview or example.com:8080 parse as URLs whose scheme is the hostname.

Destinations that don’t parse as absolute URLs, such as /pricing/ or www.example.com, are treated as paths on your own site. That means www.example.com won’t throw this error, but Astro treats it as an internal path, so it won’t send visitors to the other site.

The fix

Use lowercase https:// for anything external and root-relative paths for anything internal:

// astro.config.mjs
import { defineConfig } from 'astro/config';

export default defineConfig({
  redirects: {
    '/shop': 'https://shop.example.com/',
    '/docs-old': { status: 301, destination: 'https://docs.example.com/' },
    '/staging': '/preview/',
  },
});

For email and phone shortcuts, make a real page or a plain link, because a redirect to mailto: isn’t something a static redirect page or an HTTP Location header handles reliably:

---
// src/pages/contact.astro
---
<p>Email us at <a href="mailto:[email protected]">[email protected]</a>.</p>

Redirects from pages

Astro.redirect() inside a page isn’t covered by this config check. It accepts any string, so a bad URL there produces a broken redirect rather than an error. Apply the same rule: lowercase https:// for external targets.

For the redirect options in full, see the Astro redirects tip, and redirect must be given a location for the related build error. Our astro.config.mjs docs show the config file Komal themes use, where redirects goes, and the theme catalog has live previews of each theme. The official entry is in the Astro error reference.

FAQ

Can I redirect to an external URL in Astro?

Yes. Use a full https:// URL as the destination in redirects, for example '/shop': 'https://shop.example.com/'. Static builds write a meta-refresh page; server routes send a real redirect.

Why does HTTPS:// in capitals fail in Astro redirects?

Astro checks external destinations with a case-sensitive pattern for http:// or https://. Write the scheme in lowercase.

No. Config redirects only allow http and https external URLs. Link to mailto: addresses from a page instead.