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
redirectswhen Astro builds its route list, so it failsastro devandastro buildalike.- A destination that parses as a URL must match
http://orhttps://, and the match is case-sensitive.mailto:andtel:links can’t be config redirects; link to them from a page instead.host:port/pathwithout 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.
Can an Astro redirect point to a mailto link?
No. Config redirects only allow http and https external URLs. Link to mailto: addresses from a page instead.