5

Google Adsense now requires a file "ads.txt" in the root of the domain:

Upload the file to the root level domain of your site (for example, https://example.com/ads.txt).

I use enom with Google App Engine (python runtime). My main site is with www as a CNAME www.example.com and a redirect from naked domain to www but now I want the naked domain example.com/ads.txt to redirect to www.example.com/ads.txt.

The problem is that example.com/ads.txt redirects without the path to the home page of www.example.com/.

I don't understand how to fix it. I don't know if it should be done in the enom console, in the Google G Suite console (where I have enabled the redirect from the naked domain to www) or in my web framework (using webapp2 but changing it to flask).

Related problem is that HTTPS for the naked domain does not work (https://example.com) and does not redirect, but HTTPS works for the www and other subdomains.

How can I proceed? The site is this one and it is a Google App Engine project.

I enabled the redirect in the google GSuite web console under "domains" where it says:

Redirect the naked domain http://example.com to http://www.example.com Change redirect To enable this redirect, you must change the A record with your domain host.

Apparently the above setting once set cannot be undone. I also set the DNS records exactly as stated by Google. The site does respond at www subdomain and does the redirect but the URL path and query are not preserved.

Niklas Rosencrantz
  • 525
  • 1
  • 3
  • 16
  • 1
    "in the Google G Suite console (where I have enabled the redirect from the naked domain to www)" - How exactly have you done this? The redirect to /ads.txt should be the same redirect not an additional redirect? – MrWhite Jan 06 '20 at 09:13
  • @MrWhite I added more information. The background is that I must respond to google from my root path e.g. http://example.com/ads.txt but that does not redirect properly (the ads.txt part is dropped during the redirect). It seems like there is no way for me to even check what was the path before the redirect. – Niklas Rosencrantz Jan 06 '20 at 15:06
  • 1
    I edited your question to say "URL path" everywhere you had said "query string". You are confusing the two terms. /ads.txt is the path of the URL. It could also have a query string with a question mark like /ads.txt?query=string, but it sounds like that isn't actually the problem. – Stephen Ostermiller Jan 06 '20 at 15:55
  • 1
    It looks like this [so] question has a solution: Google App Engine Python Webapp2 301 redirect from www to non-www domain however it will only work if you manage to undo the redirection setting and let your web app handle the requests. – Stephen Ostermiller Jan 06 '20 at 16:02
  • 1
    Having an ads.txt file isn't actually required for Google AdSense. They are strongly recommending that you create one. However they are not requiring it. See Purpose of ads.txt – Stephen Ostermiller Jan 06 '20 at 16:04
  • 1
    You appear to have 2 separate redirects occurring on your site, one that preserves the URL-path, the other doesn't. 1. Non-www to www redirect (Server: ghs) that loses the URl-path and 2. HTTP to HTTPS redirect (Server: Google Frontend) that preserves the URL-path. (?) – MrWhite Jan 06 '20 at 16:05
  • So is there a way to make app-engine preserve the URL path? It's okay to modify the app code for me. – Romulus Urakagi Ts'ai Feb 05 '20 at 16:01
  • @StephenOstermiller It's a pity that we are not able to undo the redirection setting. That's the answer the support team gave me. – Romulus Urakagi Ts'ai Feb 10 '20 at 05:07
  • @Niklas Why are you using www with CNAME instead of an A/AAAA record? – Jimmy Adaro Feb 11 '20 at 14:43
  • @JimmyAdaro I don't remember. Will check and follow up a.s.a.p – Niklas Rosencrantz Feb 14 '20 at 20:31

1 Answers1

2

If you set your G Suite using the same domain and have turned on the naked domain redirect, you are stuck. I have asked the support, and they don't have a practical answer.

The cause is: G Suites and App Engine uses the same A record and G Suites will rob the routing before App Engine. Then the naked domain redirect by G Suites will replace everything by like http://www.yourdomain.com/, dropping any path or query information. There is nothing you can do other than asking Google to fix this. I don't know how to, though.

As a workaround, use another machine or cloud computing service other than Google Cloud like Amazon EC2 (I failed with S3 since it does not work well without Route 53), point your naked domain to it, then redirect with a tiny server there.

Or you can stop using G Suites for the site's domain, but I'm not sure if App Engine can handle the naked domain well.

  • Thanks for the answer. Maybe I can try and remove the domain completely from G Suite and then add it back again with no naked domain redirect. Or the workaround routing which you describe. – Niklas Rosencrantz Feb 10 '20 at 09:02