-1

I've googled, read a lot for days. And I still can't get a proper answer, so I'm gonna ask.

I have a custom domain, and I added it to deploy my app with App Engine. When I do, App Engine also creates others urls of my same app, for example:

My domain is example.com, when I deploy, I have four sites with my same website:

IMPORTANT: My ProjectID is the same name as my domain that I bought

  • example.com (and www.example.com)
  • example.appspot.com
  • staging.example.appspot.com
  • us.artifacts.example.appspot.com

So, how could I kill all those unnecessary urls and only stay with www.example.com and example.com?

(I was thinking of using Express.js to handle this, but I first would like to know if there's a better final solution. I've also tried configuring the dispatch.yaml file with it but it doesn't seem to work on this, and also with a .htaccess file to send 301 but App Engine doesn't recognize this since it's not an Apache server).

DUPLICATED, CHECK How do I prevent the "appspot.com" of my App Engine app?

franfonse
  • 189
  • 1
  • 3
  • 10
  • My bad! Call me crazy, but I asked this question in many sites; reddit, google community, etc and forgot I asked here... Thanks for letting me know, I will delete this post. now but will add the responses there. – franfonse Mar 27 '20 at 21:13

1 Answers1

4

There is no way to delete the appspot.com domains from any application on App Engine.

If you really want to "get rid of them", or making them not accessible at all, you can probably read the Host header from incoming requests on the application, and then check if the request was made to appspot.com or to your custom domain (this is done at your application level, most frameworks should allow you to do it).

Then you can redirect the request, or just return an error response, or nothing at all.

For example, with flask you can do the following:

from flask import Flask, request, redirect

app = Flask(__name__)

@app.route('/')
def read_host():
    host = request.host
    if "appspot.com" in host:
        return redirect('https://[CUSTOM-DOMAIN].com', code=301)

    # else, keep running the application normally, it means that the request
    # was made to the Custom Domain

if __name__=='__main__':
    app.run('127.0.0.1', port=8080, debug=True)

Can I ask why are you interested on doing this? As far as I know there should be no conflict or issues when the appspot domains are coexisting with custom domains, and you are not getting billed for having these appspot domain names either.

Joan Grau Noël
  • 3,084
  • 12
  • 21