Next.js Discord

Discord Forum

Rewrites with subdomains

Unanswered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
I'm trying to rewrite to a subpath using subdomains, but the approach I'm trying doesn't work. Here's the setup I have right now:
async rewrites() {
    return [
      // some other stuff
      {
        source: "/",
        has: [
          {
            type: "host",
            value: "(?<username>.*).example.com",
          },
        ],
        destination: "/personal/:username/",
      },
    ];
  },

There isn't an error message but this also doesn't work. Am I approaching this right?

5 Replies

Cape lionOP
Correct, it is in next.config.js. Right, I need to escape the dots. Let me try that.
@Sun bear if so, please exchange `value: "(?<username>[^.]+)\\.example\\.com",`
Cape lionOP
Doesn't seem to work, doesn't appear to be running