Redirect non-www to www except subdomain - nginx

I have a wildcard domain. What I want are:
When user go to mydomain.com, it should be redirect to www.mydomain.com
When user go to subdomain.mydomain.com, keep the connect
When user go to www.subdomain.mydomain.com, it should be redirect to subdomain.mydomain.com
What I can do on domain configs (change the record types) or my web server (I'm using nginx)? I searching the questions but not solve my case. Thanks.

you can use dns configuration to achieve this.
something like this
https://help.instapage.com/hc/en-us/articles/206028427-How-do-I-create-a-301-redirect-for-a-root-naked-domain-in-my-GoDaddy-account-

Related

Redirect 301 in firebase

I have to do a 301 redirect from a domain with NO www to the one with www like:
example.com -> 301 -> www.example.com (same domain)
I've bee looking to this example in the official doumentation, but it seems like the configuration doesn't considerate the whole URL path, is there any way to accomplish this?
I'm thinking about creating a separate project for the domain without www and create a firebase cloud function that takes all requests and do a redirect from there
is that the way to go? any simpler solution?
You can redirect out f the box in firebase an option I haven't noticed you just go to the following options:
Hosting
Connect domain
You can write your domain like "example.com" without www
Select the Redirect check button
Write your redirect destination, in my case, is the same domain with www
That's it!
A more specific solution for Firebase (and registrar-agnostic) was provided by Jack himself.
This is usually accomplished at the domain registrar level rather than at the app level. If your domain is with Google Domains, these would be the steps.
Edit:
Since you have your domain in GoDaddy, I would suggest to follow the instructions on their help center.

Firebase custom domain redirect www

I'm having a problem with a custom domain for a static web that I'm hosting in Firebase. When I go to mydomain.com it works fine but when I go to www.mydomain.com it's not working. Firebase hosting has an option to redirect to mydomain.com if you are trying to go to www.mydomain.com but it seems I haven't been able to verify that I own www.mydomain.com.
I verified mydomain.com using A records but when I try to verify www.mydomain.com it tells me that I should use exactly the same records I used to verify mydomain.com, so I tried to add the same A records twice but it did not work. After that I tried using TXT records to verify www.mydomain.com but it didn't work either. So, what am I doing wrong?? These are the screenshot of Firebase hosting and NameCheap.
NameCheap
the first 2 A records are to verify mydomain.com, the acme-challenge txt record is the one I'm using to trying to verify www.mydomain.com
Thanks for your help!
The directions given by Firebase are wrong. The host value should be www and not www.mydomain.com when redirecting from mydomain.com to www.mydomain.com. It happens the same when trying to verify mydomain.com but instead of www it should be # like in one of the screenshot of my answer.

Main domain redirect but not the subdomains

I have a example.net domain (no ssl). I would like to redirect this domain to https://anotherdomain.com. However I would like to keep the subdomains not redirected and continue to work as sub.example.net(no ssl).
How can I manage this? Thank you.
Kind regards

Firebase custom subdomain www redirect to non-www

I added CNAME for my.example.com and it works well, problem is with www.my.example.com.
I tried to create another CNAME record for www.my.example.com pointing to firebase, but there is SSL Certification Warning.
How can I redirect www subdomain to non www? Thanks.
According to Firebase hosting docs what you're trying to do won't work.
Subdomain depth: Subdomains of up to one level of depth are supported.
Deeper subdomains, like my.app.example.com, are not allowed.
You could potentially do the redirect through another provider. Some DNS providers for example will do redirects for subdomains.

addon domain not working on http cloudflare

I've set up a parked domain and set it's nameservers to cloudflare nameservers. but I have a strange problem. I can access the parked domain only with https (e.g. https://domain.xyz).
If I access it using http it will redirect to defaultwebpage.cgi. but if I access one of the files or folders or pages (e.g. http://domain.xyz/test) the page will load without any problems. the problem only exists on the homepage (e.g. http://domain.xyz).
the cloudflare is using flexible setting.
It's not cloudflare issues, Might be there is an issues with your local end, Please try to clear your browser cache and try again. OR try to check your domain through proxy sites.
Did you create any Page Rules in Cloudflare? I understand that you use a Cloudflare Flexible SSL certificate. In order to redirect http traffic (with our without www) to https traffic you need to add a Page Rule in Cloudflare. Did you do that?
Create a page rule like this in Cloudflare:
http://*.domain.xyz/* that redirects to https://www.domain.xyz/$1

Resources