Note: this was written on 25 March 2026. Cloudflare's site
changes quickly, but the gist of the steps should be the same.
You can set up a website and have Cloudflare serve it for free. You
get your content distributed to edge machines globally, lots of
security and protection, compression, encryption, SSL tokens,
etc. Cloudflare is a lot easier to set up and maintain than using
AWS.
Direct Upload enables you to upload your content to
CloudFlare Pages and deploy them to the Cloudflare global
network. You should choose Direct Upload over git
integration if you want to integrate your own build platform
or upload from your local computer.
Warning: if you choose Direct Upload, you cannot
switch to Git integration later. You will have to create a
new project with Git integration to use automatic
deployments. I am not sure what this entails.
Note: alternatively, You can use
cloudflare's wrangler
to do direct-upload from your computer.
On cloudflare's dashboard page, on the left side bar,
click on: Compute → Workers & Pages
Click on the blue Create application button
Click on the link Looking to Deploy Pages? Get started
Click on Drag and drop your files Get started button
enter yoursitename (e.g. www-yoursite-com) for the project
name (it will be served on .pages.dev)
drag and drop your content
To link <project_name>.pages.dev to your custom domain
name add following DNS records:
You can put your content on github (for example, create a
repo called www.yoursite.com) and then connect cloudflare to
the github repository. Then everytime you push content,
cloudflare runs a worker to publish the content. You can
control automatic builds, use branches and preview links
before publishing, etc.
Warning: if you deploy using github you cannot
switch to Direct Upload later.
Note: before beginning, I recommend you name your
github repo www.yoursite.com (changing "yoursite" and "com").
Note: you can generate preview URLS for other
branches without affecting your production deployment.
And if you do not want to trigger deployments every time
you push, you can disable deployments (see
the Other Things section).
on the cloudflare main dashboard click on the blue
+Add button
from the drop-down menu pick Pages
select import an existing Git repository
give cloudflare access to the github repo by clicking
on the link: "If your repository is not shown, configure
repository access for the Cloudflare Pages app on GitHub."
this opens a new tab and confirms access by using your
2-auth on your phone
scroll down to "Repository Access" and click "Only
select repositories" and select the repo
close the tab and go back to the cloudflare tab. You
should see a box with repo now
click on the repo box's small checkmark and then the
Begin Setup button
set the root directory to /public and click "Save and
Deploy" this creates a site at
https://www-yoursite-com.pages.dev/
click on the add a custom domain (on the success page)
(this is the same as dashboard → compute → Workers & Pages
and then selecting the Custom domains tab along the top)
hit the add a custom domain and enter it as
www.yoursite.com (full name, not just the APEX name)
wait a few minutes for the site to activate
You will need to do some more things such as redirecting the
APEX to www, setting up an error.html page, etc.
Click Other Things To Do
Note: cloudflare workers also support Git integrations to
automatically build and deploy Workers from your connected Git
repository.
learn more in workers builds
in git check-in a wrangler configuration file: wrangler.jsonc
Now that you have
connected your custom domain to cloudflare's pages mechanism,
there are several things to do to finish up (such as setting
up error pages, redirecting apex to www, toggling builds, etc).
How to redirect http to https
always use https
go to SSL/TLS
turn off encryption
go to edge certificates
turn on Always Use HTTPS
How to redirect apex/root to www
for example: https://yoursite.com to https://www.yoursite.com
cloudflare go to yoursite.com
pick DNS records on left and add DNS record:
A @ 192.0.2.1 proxied
pick rules on left side
pick template button over on the right by add (picture):
add template rule to redirect root to www
if the button is not there, then pick the template box on the page
labeled:
Redirect from root to www
use the defaults:
incoming match: wildcard pattern
request URL https://yoursite.com/*
Then redirect to target URL: https://www.yoursite.com/${1}
check the preserve query string
How To redirect a url to another one
cloudflare website
redirecting a domain
create two records on the from url:
A @ 192.0.2.1 Proxied
A www 192.0.2.1 Proxied
create rule
go to rules → overview in the left column
use template for redirect to a different domain
all incoming requests
change to static, leave the code 301
put in https://www.richgossweiler.place
Setting Up Error Redirection
When an error occurs on your site, a generic 404 page will
appear. If you create an error.html page in the root (public/error.html)
you can customize the page (just remember to use absolute references
since who knows where you are on the site the person is when they
404).
Since github also has a Pages system,
but uses a 404.html page in the repo's root (not
public/error.html), I do the following:
on github I create a 404.html page that redirects to
public/error.html
I create a public/error.html page that has full paths
(no relative links)
You can snag a template for this on github at
templateWebApp
Disable Automatic Builds on Branches
Sometimes you don't want every push to the remote github repo to
generate a build for the production deployment.
You can skip a cloudflare build by adding a prefix to the
commit message: commit -m [CI skip] ...
You can also turn off automatic builds:
Compute&AI → workers & pages → go to your pages project
go to Build → edit branch control → turn off automatic
branch deployments
or change Preview Branch ot None (Disable automatic
branch deployments)
Remove Cloudflare access to the Github Repo
To Remove cloudflare access to github repo go to the applications
page on github
https://developers.cloudflare.com/pages/configuration/git-integration/github-integration/
To Remove cloudflare access to github repo go to the applications
page on github (see
this
for more information).