Redirection from www to https - apache

I have a subdomain called for example : hello.example.com.
I can access this url using hello.example.com or https://hello.example.com.
The problem is that some of our customers use www.hello.example.com which doesnt show the website.I tried multiple redirection methods. But none is working perfectly.
Our environment : The website is hosted in 4 aws instances with 2 haproxy load balancers(total 6 instances). The domain is routed in aws Route 53.
I Tried 3 methods:
1. Adding a redirect rule in haproxy.cfg file "redirect prefix hello.example.com code 301 if { hdr(host) -i www.hello.example.com }"
Adding rewrite rule in .htaccess file in my document root
By adding www.hello.example.com in route53 ad route it to a s3 bucket with same name and using static website hosting to redirect it to hello.example.com
I am getting ssl certificate error while using the 1st method. I think this has something to do with the url being a subdomain.I have wildcard certificate for *.example.com . So this doesnt work for www.hello.example.com
The second method doesnt do anything.
And with third method i sometimes get the website using www, but not always. If i clear my cache and then search for it i will git using www, but only for 1 time.

Related

https://example.com is not accessable (unable to redirect from godaddy) when implemented with AWS

I have tried adding subdomains in CNAME record anthose are working fine (from AWS we have server endpoint instead of ip) but the format http://example.com is not accessable anyway. Tried through .htaccess file as well. Please help to resolve the issue.

Why is my IONOS 1&1 root not redirecting correctly over ssl?

I have a 1&1 IONOS domain for my heroku app. the www subdomain works fine, with a CNAME setup for it. but I'm trying to redirect the root url to the www subdomain. this also works fine for http, but if the url is typed in as https://example.com, I get a ERR_SSL_PROTOCOL_ERROR (on chrome, other browsers have different errors). this is on any device, regardless of clearing cache and history etc.
my heroku logs show it's never reached, so it must be an issue within 1&1.
theres an ssl cert set on the domain with 1and1, as well as heroku's ACM.
any ideas?
To make the four URL variations (http://example.com, http://www.example.com, https://example.com, and https://www.example.com) point to a different SSL hosted site (heroku, cloudfront, etc), you need three things in IONOS:
Under DNS settings, add a CNAME entry for the www subdomain that points to your SSL hosted site (example.herokuapp.com)
Set up an HTTP Redirect under Domain Forwarding to https://www.example.com (don't check the box that states "Also set up for www subdomain")
Make sure you have an SSL wildcard certificate for *.example.com installed and attached to your domain in IONOS
It looks like all you are missing is number 3. After that, the redirect that you have setup should work as expected.
Note: example.com should be replaced by your actual domain in all of the above.

How do you force HTTPS with Namecheap and Heroku?

I am working on setting up SSL with Heroku and Namecheap.
On Heroku I currently have the domains:
Domain Name - DNS Target
www.app.domain.io - www.app.domain.io.herokudns.com
www.domain.io - www.domain.io.herokudns.com
On NameCheap I have:
Type - Host - Value
CNAME Record - app - www.app.domain.io.herokudns.com
CNAME Record - www- www.domain.io.herokudns.com
URL Redirect Record - # - https://www.domain.io
CNAME Record - www - https://www.domain.io
What works:
www.domain.io works fine and does not redirect to include https
domain.io just fails to reach a site
https://www.domain.io works great!
https://domain.io fails to reach a site.
http://www.app.domain.io/ fails to reach a site.
https://www.app.domain.io/ fails to reach a site.
http://app.domain.io/ reached the heroku nothing there yet page.
Ideally, all pages should always redirect to include https and www. Any idea what I'm doing wrong?
I fixed the problem. I added redirect records so that if the url was entered with or without www and with or without https it would be redirected to include https and www. This required 4 redirects for the domain.
In addition, the app.domain.io url had not content because I hadn't set something up there yet. I was planning on using the app.domain.io for a new heroku app later on.
Remember to wait long enough and try clearing your cache to see if the issue is resolved.
Edit
In my domain settings under Redirect Domain
Source Url Destination Url
domain.xyz https://www.domain.xyz/
www.domain.xyz https://www.domain.xyz/
The above ensures https is always used.
In my domain advanced DNS settings under Host Records
Type Host Value TTL
CNAME Record www <link from heroku> 30 min
URL Redirect Record # https://www.domain.xyz/ unmasked
URL Redirect Record www https://www.domain.xyz/ unmasked
This is what you need to do on namecheap to work with a heroku app. There is more to do on the heroku side of things.
In Heroku under app settings there is a Domains and certificates section.
You can add your domain there. This will create a DNS Target which is what you put in the <link from heroku> block from above. Heroku will also let you use LetsEncrypt and they will automatically refresh your SSL certificate.
Remember to wait awhile between changes. DNS changes can take up to 24 hours to apply.
For anyone using Heroku, Django, and namecheap that still has a similar problem (i.e. you have a working https website, but http is not automatically routed to https), you also have to set SECURE_SSL_REDIRECT = True in your settings.py file. Making this addition fixed the issue in my case.
This change, in addition to the URL configurations posted in #Programmingjoe's answer, should fix the issue.

How to disable default website for server when subdomain is not found?

I have multiple websites hosted on server using Webmin panel version 1.660
If I enter existing subdomain like www.domain2.com everything works fine, but for non-existing subdomains like wwwa.domain2.com server loads page from domain1.com
Is there any way to disable this feature?
I would like that non-existing subdomains would show 404 error or would be redirected to appropriate domain.
If you are using Apache, search Google for 404 redirects and url rewriting. Also if you want to take it future, then you also need to configure your DNS to catch all subdomains and redirect to your HTTP server

Root Domain Not Redirecting DNSimple

I currently have my application hosted on Heroku using an SSL. I purchased my SSL and setup the SSL endpoint and all works well using DNSimple.
The issue I am having is getting my root domain to redirect to my sub domain.
Currently our application is hosted only on the secured sub domain "example.website.com" and not on the root domain "website.com"
I have tried setting up an ALIAS, CNAME and URL redirect with DNSimple but every time I type in "website.com" I receive a Heroku Error: There is no app configured at that hostname.
Perhaps the app owner has renamed it, or you mistyped the URL.
If I type in www.website.com, it will successfully redirect to my secure sub domain url. Not sure why the root itself wont transfer
*SSL was NOT purchased as a wild card. It was granted a specific sub domain url
In DNsimple you should use a URL type to redirect website.com to example.website.com. Here is a working setting (this is the reverse of yours, ie www. to none www. address);
It could be that you are not waiting long enough for the changes to take effect.