You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This sample allows subdomains to be accessed from the root domain:
https://hello.vercel.pub could be accessed by going to https://vercel.pub/s/hello
Adding in
// Block access to the subdomain pages from the root domainif(pathname.startsWith('/s/')){returnNextResponse.rewrite(newURL('/404',request.url))}
would fix it.
middleware.ts
exportasyncfunctionmiddleware(request: NextRequest){const{ pathname }=request.nextUrl;constsubdomain=extractSubdomain(request);if(subdomain){// Block access to admin page from subdomainsif(pathname.startsWith('/admin')){returnNextResponse.redirect(newURL('/',request.url));}// For the root path on a subdomain, rewrite to the subdomain pageif(pathname==='/'){returnNextResponse.rewrite(newURL(`/s/${subdomain}`,request.url));}}// Block access to the subdomain pages from the root domainif(pathname.startsWith('/s/')){returnNextResponse.rewrite(newURL('/404',request.url))}// On the root domain, allow normal accessreturnNextResponse.next();}
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
This sample allows subdomains to be accessed from the root domain:
https://hello.vercel.pub
could be accessed by going tohttps://vercel.pub/s/hello
Adding in
would fix it.
middleware.ts
The text was updated successfully, but these errors were encountered: