How to enforce www. -> https://www. on GAE with nodejs? - google-app-engine

I am trying to enforce www.example.com -> https://www.example.com & example.com-> https://example.com redirect on Google App Engine on NodeJS. I am already enforcing http:// -> https:// within express and it works as it should.
All of the existing solutions out there use a rewrite rule on nginx, however, I am not sure I can modify the nginx_proxy docker container that is running in the instance with this rewrite rule.
Any help is greatly appreciated!
Thank you.

Related

Trying to setup a NextJS website on Heroku with a custom domain from another provider (names.co.uk)

I have a website for a client which I am wanting to host on Heroku with a custom domain from https://www.names.co.uk/. https://www.names.co.uk/ has the domain name (example.co.uk) and a GeoTrust QuickSSL Premium Certificate connected to it.
I need the website to work from the following URLS and force HTTPS if someone uses HTTP:
http://www.example.co.uk
https://www.example.co.uk
http://example.co.uk
https://example.co.uk
I understand that names.co.uk does not support using CNAMES (which Heroku provides) on the root domain (example.co.uk) but I cannot figure out what I am doing wrong to prevent it from working.
I am unsure what domain names I need to add in Heroku each of them and whether I need to use the SSL certificate offered by Heroku. I also am unsure as to what I need to provide in names.co.uk in terms of A-NAMES, CNAMES and Web Forwards.
It would be much appreciated if anyone has any advice on how I can configure this properly, if it is even possible to get all these URLS to work with Heroku and Namesco.
Apologies if I haven't explained anything clearly, I'm relatively new to DNS and deployment and cannot seem to solve the issue by following Heroku's or Namesco's documentation.
Thanks in advance
Using Heroku's SSL certificate would make the process easier, so unless you have a reason to use Namecheap's SSL certificate, I recommend going with Heroku.
The Heroku certificate is automatically applied and Heroku automatically forces HTTPS.
It's recommended to use either example.com or www.example.com. Assuming you want to use the www subdomain this is how to proceed:
Redirect from example.com to www.example.com by following Namecheap's documentation on how to create a URL redirect.
Then follow the Heroku documentation to add your custom domain to Heroku:
heroku domains:add www.example.com
Then update your DNS settings. By default your DNS provider is Namecheap. See Namecheap documentation on how to create a CNAME record. Namecheap recommends against setting up a CNAME record for a bare domain, so if you want to use example.com as your preferred domain this step would be slightly different.
And that's it!
Keep in mind that the website will still be available on your Heroku domain: example.herokuapp.com. You may also want to redirect this to your preferred domain.

GAE subdomain and DNS

I have a situation where my domain is on go daddy, my web server on 1and1 and I would like a subdomain to point to my app engine.
I put setup my DNS so my domain name point to my site on my webserver, however I'm having some issues configuring my DNS and GAE to get my subdomain to point and to my app.
Any idea or suggestion?
Thank you!
Actually I found the fix.
I had to validate my domain name as <subdomain>.<domain> (That's the tricky part)
I added the provided test TXT rule with my subdomain as target instead of #.
Once that's done, GAE will provide a list of records to setup for the subdomain and instead of #, I added my subdomain everywhere and www. for the last CNAME.
You can setup specific subdomain on App Engine by following the instructions here

How to redirect a short url path to a domain?

I have the following two domains:
myVeryLongSiteDomain.com
mVeryShortURL.co
I need the following short URLs:
mVeryShortURL.com/123456789
mVeryShortURL.com/a-DSa131_
To redirect to the long site domain like so:
myVeryLongSiteDomain.com/feedback/123456789
myVeryLongSiteDomain.com/feedback/a-DSa131_
Note, how the /feedback/ url path is added
How can I make this work? Is it possible with just DNS? Do I need to host a app just for the ShortURL domain that does this redirection? FYI, my longsitedomain is a react app hosted on heroku.
What is the cleanest, right way, to make this happen?
Sadly, no, the redirection is not possible using only DNS. DNS can only gives you an IP-Address which your browser will contact.
You will need to host an app (extra server, virtual host, heroku app, ...) which does the redirection. Since it doesn't do much, this can be really lightweight. Since you are using 2 different apps, the framework you are using for your main app doesn't matter at all.
One way of doing it is to use a small php wrapper script which does the redirection and using mod_rewrite to make your apache to route all requests to your main php file. The mod_rewrite part is explained here
Another way comes without any scripting and only a webserver:
Apache: Redirect all request from old domain to new domain
Nginx: Nginx redirect all old domain subdomains to new one
If your main site uses HTTPS, which is very likely, since you are using Heroku, your redirection site should do the same. Should domains which only make redirects (aka tiny urls) be encrypted (https)?

serving another version of google app engine application - custom subdomain SSL

I was able to configure SSL for .pl to serve my appengine app over https.
My application always require https. For testing purposes I would like to be able to serve another version of my app (one that I have already uploaded). However, going to <app version>.<my domain name>.pl doesn't seem to work (I was able to do this before enabling SSL).
I purchased another SSL cert, for www.<app version>.<my domain name>.pl and configured it similarly how I configured the SSL cert for the naked domain. The problem is that under assigning urls it says "no matching urls" and doesn't allow me to enter a url.
EDIT: Turns out I can sort of achieve this by going to my apps https://..appspot.com if I disregard browser warning. Works for testing purposes fine to my mind.
To the extend I understand your question, you might be suffering from WWW and NON-WWW issue. You have configured your certificate for www...pl which should be configured on ..pl
Still it is not cleared. I can help you more accurately if you can elaborate your question.

GAE naked to www custom domain mapping does not work

I setup a custom domain on GAE using the tutorial at aral balkan to access http;//app.apspot.com at http://app.com. (I can access the app at www.app.com)
The tutorial is pretty old(Sep 2008) and it mentions
Add four Hostnames for the naked
domain (i.e., yourdomain.com without
the www) and have them point to IP
addresses 216.239.32.21,
216.239.34.21, 216.239.36.21, and 216.239.38.21.
I added the required A names to my domain dns, but accessing app.com leads me to a Google 404 page
I have used naked to www redirection on blogger using a similar method(A names provided by Google Blogger Help) and it has worked for me(it still works). However apart from the article at aralbalkan.com, I have not come across an official source which says that naked to www domain redirection using these IPs works for domains on Google Apps(which GAE uses to manage custom domains).
My Question:
Does anybody use a similar method(A names pointing to Google IPs) to resolve www domains from naked domains for custom domains on GAE? If yes, are the IPs different or am I doing it wrong?
The alternate method that I can think of using is, getting a third party host and pointing the A name of app.com to the IP address of that third party host, followed by placing a 301 redirect script to www.app.com on that host.But that will require me to manage another hosting just for naked to www redirection.
If anyone knows of any easier methods to achieve naked to www redirection on custom domains for GAE, please help.
Update:
Thank you for the answers. If it can be of any help, I am using geoscaling.com for DNS. I have an everydns account too. The domain is on namecheap and namecheap offers a freedns option too.
Update 2
Switched back my dns to namecheap. I guess geoscaling.com does not offer a 301 url redirect(correct me if I am wrong), although it's still a great service. Namecheap offers a 301 URL redirect. Should start working in some time.
While it's true Google doesn't officially support naked domains, it is possible to make this work using your registrar's DNS and Domain Forwarding tools.
For example, http://conversionsupport.com is hosted on Google App Engine, and GoDaddy is where the DNS is managed. The naked domain redirects to the http://www.conversionsupport.com subdomain using a domain forwarding rule.
Requests for the naked domain result in a 301 redirect to the www subdomain. Some SEO resources claim that using one subdomain is better for ensuring search engines don't see your site's content as being duplicative. This 301 redirect should help ensure that both naked domain and www subdomain are treated the same.
Here is a resource for Setting up URL Forwarding in GoDaddy. Note that while this is intended for Google Sites, I have confirmed that it does work on Google App Engine apps.
UPDATE:
To clarify, the naked domain itself will redirect to the www subdomain. This means that if your users type http://example.com then they'll be redirected to http://www.example.com as is the case with my original example above.
From what I understand, most Google Apps accounts are partnered with GoDaddy. Here are the Instructions from GoDaddy Support on Domain Forwarding Using a 301 Redirect..
Naked domains are not supported on App Engine. You need to use www-redirects, as you suggest.
Naked domain (e.g. yourdomain.com) support for App Engine can be setup in three steps:
Setup a naked domain redirect to a subdomain of your choice (e.g. redirect mydomain.com -> www.mydomain.com). See the App Engine FAQ, which instructs you to configure the redirect via the Google Apps control panel for your domain.
Configure App Engine to serve traffic for your custom subdomain (e.g. www.yourdomain.com) via the Google Apps control panel.
(Optionally), setup SSL for your custom domain. This step is required if you which to serve https:// traffic, but not required if you only plan on hosting http:// content.
As nick says, naked domains are not supported by app engine.
On your point of easier methods to achieve naked to www redirection on custom domains... Some DNS hosts, (for example, dyndns.com) integrate that ability into their DNS control panel. You may check with your DNS provider to see if that is the case.
With all the changes over time, I wanted to post that GAE (at least at the time of this writing) DOES support naked domains. I have this working for wdydfun.com. Follow the directions as mentioned above by Fred Sauer and it will eventually work. I'd love to provide more detail on those steps, but things seem to change frequently. You'll have to click around a bit to find where to set stuff. With the DNS propagation time that can be a bit frustrating. I recommend running
dig ns <your url>
from the command line to help see what is going on. My "www" domain was resolving to ghs.google.com and my naked domain was resolving to dreamhost where the domain was registered. After filling out the extra "A" records from the google directions, the naked domain eventually started returning different information and it worked. If you are testing this out in a browser, it's worth mentioning that at the time of this writing webkit browsers seem to be pickier than mozilla. My DNS settings:
A 216.239.32.21
A 216.239.34.21
A 216.239.36.21
A 216.239.38.21
TXT google-site-verification=W0rC...fnQ
* CNAME ghs.google.com.
Yours will probably look similar. Unless the directions have changed again. The CNAME value changed since when I first set things up, so if what I'm writing here differs from the directions on Google, trust the directions on Google. HTH.
Naked domain mapping works from the Google Developers Console.
https://code.google.com/p/googleappengine/issues/detail?id=777
We have added support for custom domains for App Engine from the
Google Developers Console, meaning you can now associate a custom
domain without first associating that domain with Google Apps.
To access the feature, visit https://console.developers.google.com/
and you will find the option to add a custom domain under App Engine >
Settings.
NOTE: Currently we do not support SSL on custom domains created
through this method (although we expect to rectify this in a future
release). In the meantime, we continue to support SSL (via VIP or SNI)
for custom domains that are created through Google Apps, and we
continue to provide free HTTPS for all *.appspot.com domains.
Alternatively, you could follow below steps which solves this problem, for sure,
Ping the website you are wanting to forward to, in order to get the
IP address if you don't know it.
"Run"; CMD; "ping yourwebsite.com"
Will display ping data and reply from IP address. Note this address.
Login to Godaddy.com to manage your account or other domain registry
site
Go to DNS Control Modify/Add "A Host"
Under "Host" enter: #
Under "Points To" Enter the IP Address you obtained earlier.
You are done! Site is forwarded without the www prefix when entered into
address bar.
More details and reference :
http://www.techproceed.com/2014/05/custom-domain-setup-on-blogger-with.html

Resources