This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Cassidy Williams
I struggled recently setting up Netlify Redirects with Astro, until I realized I needed to copy the file from the root of my directory to the built output.
Luckily, this is a very small change to make in your package.json
for your project! First of all, make sure you have a _redirects
file at the top level of your project.
Under your scripts
, change the build
command to include cp
(copy) to the final built folder. I'm just using the default naming here (dist
), but you can use whatever your site uses:
"scripts": {
// ...
"build": "astro build && cp _redirects dist/_redirects",
// ...
},
And voilĂ ! That's all you need to get it working!
Working example
Here's an example repository for this. The website (just using a basic Astro template) is deployed at astro-redirects-example.netlify.app, and you can go to /fart
and it'll redirect you to /fish
.
The _redirects
file shows you a couple options (and a fallback) for how you can set it up, and here's what the little script looks like in context!
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Cassidy Williams
Cassidy Williams | Sciencx (2023-02-04T00:20:36+00:00) Setting up Netlify Redirects with Astro. Retrieved from https://www.scien.cx/2023/02/04/setting-up-netlify-redirects-with-astro/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.