#"rewrite" subpath to subdomain

1 messages · Page 1 of 1 (latest)

steel saddleBOT
#

Hi @desert pecan. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To achieve the behavior you described, where requests to www.mydomain.com/faq and its subpaths are rewritten to faq.mydomain.com and its corresponding subpaths, you can use Vercel's rewrites feature. However, the article you referenced does the opposite (rewriting a subdomain to a subpath), so it won't directly help you.

Instead, you can configure your next.config.js or vercel.json to handle this rewrite. Here’s how you can set it up:

Using next.config.js

If you are using Next.js, you can define the rewrites in your next.config.js file:

module.exports = {
  async rewrites() {
    return [
      {
        source: '/faq/:path*',
        destination: '<https://faq.mydomain.com/:path*',>
      },
    ];
  },
};

Using vercel.json

If you prefer to use a vercel.json configuration file, you can define the rewrites like this:

{
  "rewrites": [
    {
      "source": "/faq/:path*",
      "destination": "<https://faq.mydomain.com/:path*">
    }
  ]
}

Explanation

  • source: The path pattern to match on your main domain (www.mydomain.com). The :path* wildcard will match any subpath under /faq.
  • destination: The target URL to rewrite to, which includes the subdomain (faq.mydomain.com). The :path* wildcard ensures that the subpath is preserved in the rewrite.

Additional Resources

For more details on how to configure rewrites, you can refer to the following documentation:

#

By setting up your configuration as shown above, you should be able to rewrite requests from www.mydomain.com/faq to faq.mydomain.com seamlessly.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@desert pecan kapa.ai is still learning and improving, please let us know how it did by reacting below