How to setup static website with subdomain?

I setup a simple static website and it is working fine. I want to add a subdomain. The setup current is using github to publish the pages to Cloudflare. I am on the free plan.

How do I tell Cloudflare where to find the files for the subdomain? Is there a way to do it with 1 github repo? I think I can create a 2nd repository and then map that to the subdomain on Cloudflare (though I am not totally sure on that - this is my first attempt to use Cloudflare so I am just learning).

But it seems like it would be nicer to just have 1 github repo. And have something like a [subdomain] folder in the main repo and then tell Cloudflare to use that directory for [subdomain] maybe?

What would be your suggestion for the simplest way to do this?

Yes, you can now do this with one Github repo. It will be a separate Pages project in your Cloudflare dashboard, with the subdomain added to it. See the docs here:

1 Like


The web page says “go to your Pages project > Settings > Builds & deployments > Build watch path”

Trying to find where that is clicking through lots of menus isn’t easy imo. For future readers you go to[your “account number”]/pages/view/[your “pages project name”]/settings/environment-variables

It also seems like “excluding a path” just excludes it from updating (doesn’t remove it from the “Cloudflare site”)?

So when I created the subdomain and "excluded the main repo and included just a subdirectory it is including the whole site. But for that site [https://[project-name][subdirectory-name] the subdirectory displays as it should.

So I tried using that address (with the subdirectory included) as the “content” DNS item but my guess maybe Cloudflare doesn’t like the / in the “content” DNS field? Because the subdomain generates an error page

Error 1016
You’ve requested a page on a website that is on the Cloudflare network. Cloudflare is currently unable to resolve your requested domain

Though if it is as simple as no / is allowed in the DNS content field I would think Cloudflare would block me using it at all. So maybe it is just some special issue it doesn’t like…

I will likely look at it more tomorrow. If anyone has suggestions, please let me know.

The “Build Watch Path” controls when a new build is triggered. What files and directories should trigger a build for that project when they are changed. This might differ from the actual output directory, depending on what you’re using to build your site.

The next setting, “Build Configurations”, lets you set the output directory for that project. So if this site is in a subdirectory, you can set “Build output directory” to use that subdirectory. This controls the directory that your subdomain will point to.

Don’t create DNS entries yourself for Pages projects. Just add the custom domain to the project and the DNS will be done for you.


Thanks, I think I have it working. Your help has been great I think I would have had great difficulty getting this working without that help. Cloudflare seems extremely powerful but also fairly confusing (to me anyway) to get started with.

It seems like with the “monorepo” I should have the different sites/sub-domains each in their own directory?

I had it setup for the base site (so the repo was just in the root directory). I added the subdirectory. So I added a folder to put the subdirectory files in. With your latest details I was able to get the subdirectory working properly.

But as far as I can tell the “build watch path” lets you exclude directories but the “build environment” does not let you exclude paths. So I end up with the subdirectory also showing up at[subdirectory]. I guess I am suppose to setup the repo so the “main site” is in a subdirectory (like I have the subdomain in now). Then in the “build settings” for the main site I can point to that directory (just like I have setup for the subdirectory).

Leaving some additional text that may help others trying to do what I was trying to do.

I find navigating around the Cloudflare admin area pretty confusing. I can see there is tons of power to do many things (so that results in lots of links… that sometimes make it hard to find where you want to go).

To setup the subdirectory you have to (or at least this is the way I figured out), well actually I already forget while trying to retrace my steps. I think maybe I went into “workers and routes” and then add a clicked “create application” and then had to switch from workers to pages by clicking a link. And then I connected to a git repo…

Anyway I did find you have to find your way to “Workers & Pages Overview” to be able to see the subdomain project. The website project is easy to find in various ways but none of those pages show you the subdomain project other than the “Workers & Pages Overview.”[“account number”]/workers-and-pages This link can be found in the long list of items under “go to” you have to go down about 100 items all the way into “account wide items” so past all the website level products (where I expected to find it).

And you can’t make it show up by making it a website project of its own (so that it is not hidden so far under many links) because that can only be used for a root domain. That is ok. But why Cloudflare doesn’t show the subdomain projects on the main domain project makes it much more annoying to find your way around and get things done. I am sure as one learns how things work and if you are constantly workin on the sites, it gets somewhat easier (but if you go away for 6 months and then need to edit something it seems to me it is going to be confusing to find things…).

I am going to create my own Cloudflare bookmarks to help me be able to find pages on the admin system I want to find again.

FYI, Cloudflare limits me to 5 custom domains connecting the same GitHub repo. They don’t give you any details on that (like 3 of 5 connections used… or something). Just when you try to connect the 6th one it is blocked with a message that no more connections allowed.

You can just create a separate Github repo and move the other sites into it and then keep connecting them. I have a site with 8 subdomains so it will fit in 2 “monorepos”. The docs say there is a limit of 5 pages projects per repo (but putting an indication in the UI seems like it would be useful to me).

I really like Cloudflare so far, but it is certainly a bit confusing to get started with.

You’re right; I forgot about that limit (I don’t use monorepos myself).

This is a raisable limit. You can fill out this form and provide your use case.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.