大网数据广告活动
网站运营与故障问答

How can I redirect my Google App Engine naked domain to www and preserve the URL path

· 52CE 我爱测

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 mai…

问题原文

原帖链接 · Niklas Rosencrantz · CC BY-SA 4.0

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.

已采纳解答

原帖链接 · Romulus Urakagi Ts'ai · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2019-12-31)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。