Guides for redirect to app.site.com
Answered
Chalcid wasp posted this in #help-forum
Chalcid waspOP
How should I approach this requirement where I have my site at site.com. And I would like for the main application to live at app.site.com. How should I approach this?
39 Replies
@Chalcid wasp How should I approach this requirement where I have my site at site.com. And I would like for the main application to live at app.site.com. How should I approach this?
Do you have a domain? that needs to be either done by changing nameservers or by adding records
Easiest solution is to use vercel nameservers, and add that domain to vercel i.e. app.site.com
vercel will handle the rest
you can use a permanent redirect like this: https://nextjs.org/docs/app/api-reference/functions/permanentRedirect
Or you can route inside your domain config, that you want to redirect from site.com to app.site.com
permanentRedirect(path, type)Or you can route inside your domain config, that you want to redirect from site.com to app.site.com
Northern Wheatear
I think @Chalcid wasp meant a multi tenant app
Read through this post: https://vercel.com/guides/nextjs-multi-tenant-application
Read through this post: https://vercel.com/guides/nextjs-multi-tenant-application
well, we never know when OP is not answering ^^
Northern Wheatear
Thats true lol
Wow the third person that said that 😂
Chalcid waspOP
Sorry, guys! Was night time in my time zone
I’m thinking of apps like Tinybird or WorkOS where their site.com is used for landing/marketing. And when you’re signed it, you’re redirected to app.site.com
@Anay-208 Do you have a domain? that needs to be either done by changing nameservers or by adding records
Chalcid waspOP
Yes, I do have a domain
@Chalcid wasp Yes, I do have a domain
Can you explain further what you need to do
Do you want to redirect users from site.com to app.site.com?
if that, set up a redirect in site.com to app.site.com
and use app.site.com as domain
I'll explain steps in detail if you want
Chalcid waspOP
I still want to use site.com for things like /pricing, /about, /contact, for example. However, for paths like /signin, /signup, /slug/dashboard I want them to be at app.site.com
Chalcid waspOP
Ahhhhh. Yes, yes. That does make sense
For the sake of knowledge haha, how would you approach the “difficult†way if you were to do this with one app
@Chalcid wasp For the sake of knowledge haha, how would you approach the “difficult†way if you were to do this with one app
For that, You'll have to create a wildcard
for 1 nextjs app
wait not wildcard
You have to create 2 domains, pointing to same app
add 2 domains*
Answer
And in nextjs app only, you'll have to redirect from app.com to app.site.com/signin, it'll be in the same app. However, if you want it such that app.com/signin doesn't work, you might need to use a condition for that, or middlewares.
Also, mark my message as a solution
its not actually difficult, but time-consuming
Chalcid waspOP
How would I test this out in localhost?
If at all possible
@Chalcid wasp How would I test this out in localhost?
You'll have to run a app twice, each on different port
in .env, set up both the urls, including values for condition
window.location.host, to see the hosthere is a example condition(Could be inefficient and could have errors)
const pagesInSubdomain = ["/login"]
//sign in page
if(pagesInSubdomain.includes(window.location.pathName) && window.location.host !== process.env.SUBDOMAIN_URI) {
redirect(process.env.SUBDOMAIN_URI + window.location.pathName)
}it just gives you a idea on how to achieve this
Chalcid waspOP
Ahhhh. Okay, okay. Thanks a bunch!!