GitHub Pages https/www Redirect - dns

How can I get https://www.test.com to redirect to https://test.com when using GitHub pages to host a static website?
I recently enabled TLS (provided by GitHub/Lets Encrypt) for my static site by setting A records at my DNS provider (namecheap). I've also chosen to "Enforce HTTPS" option in my GitHub repository's settings, which handles redirecting requests from http://test.com to https://test.com. I have a redirect configured through my DNS provider which forwards http://www.test.com to https://test.com, but the one missing piece of the puzzle is forwarding https://www.test.com to https://test.com.
Regarding this issue, GitHub says, "If your domain has HTTPS enforcement enabled, GitHub Pages' servers will not automatically route redirects. You must configure www subdomain and root domain redirects with your domain registrar."
... and my DNS provider says, "It is not possible to set up a URL redirect in the account for the TCP port forwarding from http://www.domain.tld (uses port 80) to https://www.domain.tld (working via port 443)."
I seem to be caught in an infinite loop of the two services saying the other should provide this functionality.

What worked for me:
Change your custom domain to be prefixed with www., like this:
Save the settings and wait until www.example.com resolves and works.
Remove the www. prefix and save again.
Wait for browser and DNS caches to invalidate.
All combinations should lead to https://example.com/ and no SSL error should appear.

GitHub Pages handles redirection between the apex domain and www subdomain automatically as long as you configure the DNS records correctly.
From the GitHub Pages documentation on configuring an apex domain:
If you configure the correct records for each domain type through your DNS provider, GitHub Pages will automatically create redirects between the domains. For example, if you configure www.example.com as the custom domain for your site, and you have GitHub Pages DNS records set up for the apex and www domains, then example.com will redirect to www.example.com. Note that automatic redirects only apply to the www subdomain.
While the docs discuss redirecting from the apex domain to the www subdomain, the reverse direction works as well.
If the apex domain is the desired target (as in this question): set the custom domain value to just example.com.
If the www subdomain is the desired target: set the custom domain value to www.example.com.
Again, this works as long as DNS records are correctly configured for both the apex domain and www subdomain, as described in the docs.
Not the point of this question, but the question When should one use a 'www' subdomain? offers some good insight on using the www or not.

Related

Azure dns forward www to naked no-www

I own for a website (example.com (GoDaddy)) and I set the name servers to Azure and manage DNS from there. I don't know enough about DNS to know how to properly do what I'm trying to do or the pros/cons. I have SSL always set in my AppService.
I want www.example.com to forward to example.com (on both http and https). Currently, I have both registered and bound to a cert in the AppServices and it works over https. The following links work in fact.
http://example.azurewebsites.net forwards to -> https
https://example.azurewebsites.net works/secure (seems to be using *.azurewebsites.net cert)
http://example.com forwards to https://example.com
https://example.com works/secure using example.com cert
http://www.example.com (forwards to https)
https://www.example.com (works using example.com cert).
So, all of these work and are secure... but I'd like ALL of them to forward to the naked and secure: https://example.com
I setup (In Azure) www CNAME to point to example.azurewebsites.net. Can I get this to happen through dns configuration or do I need to modify the actual AppService code to detect www and forward?
Also, if later I want someOtherAPI.example.com (can it point to another totally different AppService and use the same cert or will it need another cert?
It seems you want to know two points in your question:
So, all of these work and are secure... but I'd like ALL of them to
forward to the naked and secure: https://example.com
By default, Azure provides a wildcard cert *.azurewebsites.net for the domain azurewebsites.net, so you could use https for the domain and its subdomain. If you want to forward all traffic forward to the URL https://example.com, you need to change your code like URL rewrite or URL redirect in the web.config file. View More details here1 and here2
Also, if later I want someOtherAPI.example.com (can it point to
another totally different AppService and use the same cert or will it
need another cert?
The SSL cert DNS name must match the domain name in the website URL. So if you want to secure the website for the domain someOtherAPI.example.com, you need an SSL cert DNS name as someOtherAPI.example.com or wildcard domain *.example.com for this website.
Hope this could help you.

Custom Domain to Azure CDN Endpoint with and without www

I have created an Azure CDN, an endpoint and working fine.
Created a CNAME www.mydomain.com to myazurecdn.azureedge.net
Created another CNAME mydomain.com to www.mydomain.com
In Azure Endpoint, Custom Domain, I updated www.mydomain.com and it got propagated.
Now, when I navigate to www.mydomain.com, everything works fine but when I navigate to mydomain.com i get below response.
Our services aren't available right nowWe're working to
restore all services as soon as possible. Please check back soon.
Note: As Azure endpoint accepts multiple custom domain, I could add both www.mydomain.com and mydomain.com but it is not correct way, as I have many <a> tags with www.mydomain.com/link.
What to be done now to instruct system to use same route for mydomain.com and www.mydomain.com?
Is domain redirect from domain.com to www.mydomain.com only option?
Have a look at this,
A custom domain and its subdomain can be associated with only a single
endpoint at a time. However, you can use different subdomains from the
same custom domain for different Azure service endpoints by using
multiple CNAME records. You can also map a custom domain with
different subdomains to the same CDN endpoint.
You can use different subdomains in the same endpoint. Alternatively, I think you also could create two endpoints, one is for the root domain without www, the other is for a subdomain with www.
I would say, you can implement redirection in your server or CDN.
When someone tries to access example.com, you can do a 301 by sending http://www.example.com in the location header.

CNAME on a custom domain is changing the url on the address bar with a 301 redirect

I am building a web app and i will like to access the application from another domain using a CNAME record.
The app is running on my main domain (my-domain.com) and i have a second domain (another-domain.com)
I have set up the CNAME for another-domain.com to point to my-domain.com but whenever i visit another-domain.com i get a 301 redirect to my-domain.com
Is there something i need to do that i haven't done yet?
This is my first time working with CNAME so suggestions are welcomed.
Thanks
CNAME is a DNS alias for an A record (IP Address).
DNS doesn't know anything about 301 Status (which is part of the HTTP protocol).
So the 301 response you're getting is coming from your website (or possibly your firewall/router/load balancer). Check your server logs to see which application is returning the 301 (apache, IIS, NGinX, HA-Proxy, etc), then check the configuration to ensure it's performing the way you want.
For example, in Apache you might have created a new VirtualHost for another-domain.com with
Redirect permanent my-domain.com
If you want the same web content displayed no matter what the domain, consider changing the my-domain.com VirtualHost configuration, adding :
ServerAlias another-domain.com

Redirect TLD and 'blog' subdomain on github pages

I started with GitHub Pages and I don't manage to configure my DNS and my GitHub Repository as I want to.
I would like to redirect both mydomain.com and blog.mydomain.com to username.github.com.
I put mydomain.com in the CNAME file in my GitHub repository and added A records for # to 204.232.175.78 and two CNAME records for www and blog to username.github.com the URL blog.mydomain.com give me a GitHub 404 error.
What is wrong with my configuration?
Per the GitHub Pages help page,
You can only have one custom domain for any given set of Pages. If you
want multiple domains to point to the same pages, you will need to
find a service that can redirect the other domains to your Pages
domain.
If you would like to redirect both subdomains (www and blog) to username.github.io, you could use your DNS provider to set up a forward (w/o masking) from www to blog. Then, if a visitor goes to www.mydomain.com or blog.mydomain.com, they'll see the contents of username.github.io, and the address bar will read blog.mydomain.com.

Redirect non-www to www using DNS Zone Editor?

I've just purchased a new traffic tracking service, which requires my domain (registered at GoDaddy) to have a CNAME record pointing to their servers.
I've done that fine, and it's now working.
However, when typing it in without the "www", I get a 404 error page.
My question is, what would I type in the DNS Zone Editor to redirect my "non-www" domain to the "www" domain?
For example, I need my URL to do this…
http://mydomain.com/1234 --> http://www.mydomain.com/1234
Would it be done using an "A name record" or something? Or another way?
I've searched everywhere and can't find a solution that works, so hopefully you can help.
Thanks,
James.
Assuming you just want to send all traffic from mydomain.com (known as your 'naked' domain) to www.mydomain.com you should be able to use domain forwarding. In GoDaddy this will be in the Domain Manager under "Domain Information" at the bottom.
For those having their servers with AWS and domain registered at Godaddy:
I set up my A record with 2 entries (Host: # and www) as below to redirect to my server in AWS through the public ip. This catches the URLs with/without the www prefix
Using DNS Manager we cannot redirect our (naked) domain
(example.com)
to www version
(www.example.com)
we need web hosting for this purpose. because I try it but results are zero. Using domain hosting it is imposible in my views..
By using Forward domain how can i forward the is here. In screen short. there is a option Forward to
My domain is in
(www.example.com)
Version. if i use this option it will redirect to
(example.com)
According to these settings.
Note my :
1] Domain name : GoDaddy
2] Hosted (code) : Heroku (minimum $25/month dyno, dyno is virtual machine, dyno is equivalent to EC2 of AWS)
3] SSL certificate : Bought on GoDaddy ; and endpoint on Heroku (heroku minimum SSL endpoint on $20/month)
These were working :
https://www.example.com/
http://www.example.com/
www.example.com
These were not working :
example.com
http://example.com/
https://example.com/
My heroku ssl add on had :
www.example.com
example.com
Solution:
step 1:in cmd/shell
Copy IP address above and use in step 2
step 2:in GoDaddy account
DONE!!!
Note :
1)remove forwarding if you have to use this solution
2)CNAME - www - sslendpoint

Resources