#Only get redirect on localhost but when building->starting app the redirection stops working.

3 messages · Page 1 of 1 (latest)

dark wyvern
#
  if (provinceCookie) {
    const originalPath = req.url; // Use req.url to get the full URL, including the hostname and protocol

    if (provinceCookie === "AB" && !originalPath.includes("/AB")) {
      const url = new URL(originalPath);
      if (!url.pathname.includes("/AB")) {
        url.pathname = `/AB${url.pathname}`;
        return NextResponse.redirect(url.toString());
      }
    }

    if (provinceCookie === "BC" && originalPath.includes("/AB")) {
      // Updated regular expression to match "/AB" or "/AB/" at the start of the pathname
      const regex = /\/AB\/?/;

      if (regex.test(originalPath) && originalPath !== "/") {
        const redirectedPath = originalPath.replace(/\/AB\/?/, "/"); // Replace "/AB/" or "/AB" with "/"
        return NextResponse.redirect(redirectedPath);
      }
    }

    // If the user has a value for the provinceCookie, simply return the requested path
    return NextResponse.next();
  }
frigid tangleBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

dark wyvern
#

seems like NextResponse.redirect(redirectedPath) just doesnt redirect