Report this

What is the reason for this report?

App Platform: Set subdomain to redirect to folder on main domain

Posted on December 6, 2025

I’m using app platform for a site, and I want to set it up to redirect a subdomain to a folder of the main domain. e.g.:

foo.example.com => example.com/foo

how do I do this? I’ve already setup foo.example.com as a custom domain in my app, but I can’t figure out the next step. I tried to do it via CNAME, but that tells me that example.com/foo is an invalid alias



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

DNS can only map hostnames to IPs or other hostnames. It does not know anything about paths like /foo, so doing foo.example.com to example.com/foo purely with a CNAME generally is not possible.

Since you are on App Platform, this likely has to be handled at the application or proxy level, not in DNS.

One option, if you control the app code, is to check the Host header for foo.example.com and return a 301 redirect to https://example.com/foo. That approach works in most frameworks.

Another possible option is to route things internally so that requests coming to foo.example.com are served from /foo, but that usually requires more custom proxy logic and is not always needed.

As far as I know, App Platform does not currently have a built-in DNS-level feature to redirect a subdomain to a path on another domain. The URL rewrite feature is for paths on the same host, not for mapping different hosts.

So in practice, the custom domain setup plus an app-level redirect is usually the safest way to do this.

Heya, @huntybunz

You can’t do this with DNS. A CNAME can only point to a hostname, not a URL path, so example.com/foo will always fail.

You need to add a redirect inside your app on App Platform. Attach foo.example.com to the app, then in your app code or framework config return a 301 redirect to /foo.

Regards

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.