#Hi
30 messages · Page 1 of 1 (latest)
🔎 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)
have you tried using redirects in next.config.js?
https://nextjs.org/docs/app/api-reference/next-config-js/redirects
try this
What i want is that if there subdomain i will run a function and if i get the desired result then do some action else redirect to the main domain like. So that is why i am using middleware.
well you just said you want to redirect in the question
are you sure the condition matched in hostname === 'go' && path === '/'?
Yes
i haven't pushed it to the repo yet
I just did a quick test and it works
import { NextRequest, NextResponse } from "next/server";
export function middleware(req: NextRequest) {
const hostname = req.headers.get("host")?.split(".")[0];
const url = req.nextUrl.clone();
const path = url.pathname;
const domain = "";
if (hostname === domain) {
} else {
if (hostname === "go" && path === "/") {
return NextResponse.redirect("http://localhost:3000/p");
}
}
}
its working
was not before
so here i have given the exact url but how to do when it is deployed
if you are redirecting to same domain, you can do this
NextResponse.redirect(new URL('/home', req.url))
otherwise create the domain in env variable