How do I route a subdomain to a NextJs route - next.js

I have a NextJs app with 2 routes (/ and /blog) configured as:
pages/index.tsx
pages/blog/index.tsx
When I deploy them on vercel, everything works fine but I want to have a subdomain for /blog like blog.example.com. So whenever an user goes to blog.example.com, I want to redirect them to example.com/blog. So in my registrar I added blog as cname and in my vercel, I added that subdomain. But the problem is vercel doesn't show any options for this redirection. It only allows redirections to other domains or to a different git branch but not to a domain with a route.
Basically I want to route blog.example.com to example.com/blogon my vercel config. But Vercel doesn't allow me to add a route along with the domain.
In my registrar, my dns is configured as following:
example.com A <some ip>
blog.example.com CNAME cname.vercel-dns.com.
www.example.com CNAME cname.vercel-dns.com.
So what are my options? I know I can just create 2 different projects, one for / and one for /blog and use monorepos but it seems like an overkill as my / webpage is very simple.
Edit:
Found an answer where they suggest using wildcard domains on vercel and then in the NextJs app, parsing the url, and then doing the redirection... which is fine, I guess. But it seems a bit hacky? Shouldn't this redirection logic be done in the cloud management side and not within my webapp?

So looks like I was approaching it from the wrong end. The registrar, in my case google domains, allows domain forwarding. So I removed my sub domain from the cname and added it here. Problem solved.

Related

Redirect subdomain.example.com to example.com in firebase web hosting, but keep the URL intact

I have hosted https://example.com on firebase web hosting
Now, I would like https://subdomain.example.com to go the https://example.com hosted site, but URL should be intact and still show https://subdomain.example.com.
I will handle the UI on Web Pages based on the subdomain name and hence retaining subdomain is very important.
If I use 'redirect to existing domain' option, then URL is changed. Is there any configuration which allows me to do this on firebase?
Website is built using AngularIO, so any suggestion as part of Angular deployment is also welcome.
While there are similar questions on the site, I couldn't find any solution. So, asking here again with more clear description. Thanks for your help.
Just connect subdomain.example.com but don't set it as a redirect. All domains/subdomains connected to a project that are not redirects will resolve the same content.

Mapping elastic beanstalk (wordpress blog) to subdomain

So I have set up my static website via S3 and have attached it to my domain example.com.
Then, I have launched a separate wordpress blog via Elastic Beanstalk, let's say exampleblog.us-west-2.elasticbeanstalk.com.
I have already configured my CNAME settings in Route 53 such that blog.example.com maps to my elastic beanstalk site (exampleblog.us-west-2.elasticbeanstalk.com), except, once I start clicking around on the blog itself, the URLs all become exampleblog.us-west-2.elasticbeanstalk.com/NAME-OF-PAGE
How do I get a complete subdomain redirect? i.e., I want all of the pages in my blog to be in the form blog.example.com/NAME-OF-PAGE
Thanks!
Okay -- I have actually figured this out myself so just will share in case anyone else has the same question:
It's really simple - You just need to access Wordpress > Settings > General and then update your site address (URL) to your subdomain (in my case, blog.example.com).
Boom!

Is it possible to host site on meteor.com and have a naked domain from namecheap?

I've got a domain, freegreen.space, that I'd like to host on meteor.com as freegreen.space. I'd also like www.freegreen.space to redirect to freegreen.space. I've got two DNS entries, CNAME www origin.meteor.com and URL Redirect # http://www.freegreen.space. Is it possible to have www.freegreen.space redirect to freegreen.space, and host on meteor.com?
I haven't found a good way of doing this. Probably cause meteor.com isn't ment for production hosting.
What you can do though, is the following:
DNS
A: # 107.22.210.133
CNAME: www freegreen.space
Deployment
You need to do meteor deploy freegreen.space then meteor deploy www.freegreen.space
Now you will have 2 deployments of your website. It's ridiculous but it's a work around.

DNS_PROBE_FINISHED_NXDOMAIN Subdomain and Domain Issue

I have a basic wordpress website with a few simple plugins such as gravityforms etc. For the sake of this question the site has a domain of domain.com
To manage user input we have another system on a subdomain, sub.domain.com
Some users are intermittently receiving the following error 'DNS_PROBE_FINISHED_NXDOMAIN' whether that be on the domain or subdomain.
Is it possible that this issue is an issue on one of domain.com or sub.domain.com and the users browser shows errors with both purely because the urls have the same domain?
Add wildcard DNS on cpanel. You can create wildcard dns following instruction on the below.
http://www.webhostinghub.com/help/learn/cpanel/manage-domains/how-to-set-up-wildcard-subdomains

Changing welcome screen of Nginx

Hi i have setup nginx and works fine. I have added some config to accept the subdomain and that is also working fine no problem. My major concern is i have a meteor app that takes the username and creates nginx subdomain config in the fly. and currently i have listed * in my A/AAAA record in server so it accepts all subdomain. now i wanna show different view if the user request the subdomain that is not created in nginx config.
for eg,
i have setup subdomain A,B in nginx config pointing different application
A.example.com //works fine
B.example.com //works fine
if i Enter
C.example.com // shows me welcome to nginx screen
I wanna show my custom page there
Thanks in advance
This has nothing to do with Meteor, rather it is about setting up your nginx's default page. Try the below links
http://gpiot.com/blog/setup-default-server-landing-page-with-nginx/
NGinx Default public www location?

Resources