Set up adsense on koyeb with domain

Hey there,

I’ve got a problem where I’m stuck.
I managed to set up my domain to redirect to my koyeb hosted web app.
Now I want to integrate Google Adsense and need to validate my ads.txt file.
I set up a route in my Flask app /ads.txt, to point to the file in my static folder.
If I navigate to the www.mydomain.com/ads.txt, everything works as expected.
But sadly Google needs to navigate to the domain without www - and that’s where I’m stuck, since my DNS always redirects from mydomain.com/ads.txt to the www version start page.
What settings do I need (in my DNS?) to make this work?
Thanks for your help.

Hello!

The DNS translates a domain name to an IP address. If I understand correctly, when you access mydomain.com/ads.txt, you are redirected to www.mydomain.com/ads.txt. It means the DNS is well configured: both www.mydomain.com and mydomain.com are resolving to the same IP address.

When you access mydomain.com, your browser makes a HTTP query and the server responds with a redirection to www.mydomain.com. You need to find what is making this redirections, and I see two options.

First, it might be your flask application. Check the logs of your application: do you see a HTTP/302 or HTTP/301 response when you query mydomain.com? If yes, it means your application is configured to perform this redirection. Since your browser might have cached the redirection, do not use your browser to make the query but use cURL instead.

The second option is another component, a load balancer for example, is first receiving the request and performs the redirection.

Hey Julien,
thanks for your explanation.

Not quite, though. If I access mydomain. com/ads.txt I’m redirected to www.mydomain. com since I followed the steps in your documentation to set up a custom domain.

I set up a CNAME to my koyeb app for www.mydomain.com and set up a DNS from mydomain.com → www.mydomain. com
That works well, but if I want to access a sub page via mydomain. com/subpage, I’ll always end up at www. mydomain. com

I tried to disable the DNS and code it into the Flask app, but that did not work. I always saw a “your page is not secure screen” (altough I redirected to the https:// version…)
If I enable the DNS, the path is not followed since the DNS is obviously redirecting before my application gets the request.

So, I’m stuck.

(I had to split up the domains since new users can only post two domains… pretty annoying)

I learned that it might not be possible to set it up the way I need it with my old domain service, so I transfered to Namecheap (they allow ALIAS entries).
That’s how I set it up in Namecheap:

Set up on Koyeb for www domain works and website is available via www domain.
I tried to add non-www domain in Koyeb too, but configuration on Koyeb always fails.

Any suggestions?

I’m sorry, I don’t see what could happen. Could you join our slack community? https://community.koyeb.com/

You can contact me privately (Julien Castets), and we can investigate.

We were able to solve my problem.
Solution was to transfer my domain to Cloudflare, so I was able to use both ALIAS and CNAME record and point them to root/www domain.

Works perfectly fine now, thanks again for your help @Julien_Castets1

1 Like