Skip to main content

Command Palette

Search for a command to run...

How to setup url redirection on Vecel

Published
2 min read
How to setup url redirection on Vecel
E

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:

  1. Create a vercel.json file: If you don't have a vercel.json file in the root directory of your project, create one.

  2. 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. 301 indicates a permanent redirection. You can also use 302 for temporary redirection.

  3. Deploy your changes: After adding the redirect rules to vercel.json, commit your changes and deploy your project to Vercel. Vercel will automatically detect the vercel.json configuration and apply the redirect rules during deployment.

  4. Testing: Once the deployment is complete, test the redirection by visiting the old URL (/old-url in the example). It should redirect you to the new URL (/new-url in 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.

More from this blog

T

Tenten - AI / ML Development

225 posts

🚀 Revolutionize your business with AI! 🤖 Trusted by tech giants since 2013, we're your go-to LLM experts. From startups to corporations, we bring ideas to life with custom AI solutions