How to setup url redirection on Vecel

Crafting seamless user experiences with a passion for headless CMS, Vercel deployments, and Cloudflare optimization. I'm a Full Stack Developer with expertise in building modern web applications that are blazing fast, secure, and scalable. Let's connect and discuss how I can help you elevate your next project!
Setting up URL redirection on a Vercel project is quite straightforward. Vercel allows you to define rewrite and redirect rules in a configuration file called vercel.json. Here's how you can set up URL redirection:
Create a
vercel.jsonfile: If you don't have avercel.jsonfile in the root directory of your project, create one.Define redirect rules: Inside
vercel.json, you can define redirect rules using the"rewrites"property. Here's an example of how to redirect from one URL to another:json
Copy code
{ "rewrites" : [ { "source" : "/old-url" , "destination" : "/new-url" , "status" : 301 } ] }"source"is the URL path you want to redirect from."destination"is the URL path you want to redirect to."status"is the HTTP status code for the redirection.301indicates a permanent redirection. You can also use302for temporary redirection.
Deploy your changes: After adding the redirect rules to
vercel.json, commit your changes and deploy your project to Vercel. Vercel will automatically detect thevercel.jsonconfiguration and apply the redirect rules during deployment.Testing: Once the deployment is complete, test the redirection by visiting the old URL (
/old-urlin the example). It should redirect you to the new URL (/new-urlin the example).
That's it! You've set up URL redirection on your Vercel project. You can add more redirect rules as needed by adding additional objects to the "rewrites" array in vercel.json.






