Migrating from Workers Sites to Pages
Cloudflare Pages provides built-in defaults for every aspect of serving your site. You can port custom behavior in your Worker — such as custom caching logic — to your Cloudflare Pages project using . This enables an easy-to-use, file-based routing system. You can also migrate your custom headers and redirects to Pages.
You may already have a reasonably complex Worker and/or it would be tedious to splice it up into Pages’ file-based routing system. For these cases, Pages offers developers the ability to define a
_worker.js file in the output directory of your Pages project.
Remove unnecessary code
Workers Sites projects consist of the following pieces:
- If using a static site tool, a build directory (called
- A Worker application for serving that build directory. For most projects, this is likely to be the
When moving to Cloudflare Pages, remove the Workers application and any associated
wrangler.toml configuration files or build output. Instead, note and record your
build command (if you have one), and the
bucket field, or build directory, from the
wrangler.toml file in your project’s directory.
Migrate headers and redirects
You can migrate your redirects to Pages, by creating a
_redirects file in your output directory. Pages currently offers limited support for advanced redirects. More support will be added in the future. For a list of support types, refer to the .
Your custom headers can also be moved into a
_headers file in your output directory. It is important to note that custom headers defined in the
_headers file are not currently applied to responses from Functions, even if the Function route matches the URL pattern. To learn more about handling headers, refer to .
Create a new Pages project
Connect to your git provider
After you have recorded your build command and build directory in a separate location, remove everything else from your application, and push the new version of your project up to your git provider. Follow the to add your project to Cloudflare Pages, using the build command and build directory that you saved earlier.
Using Direct Upload
If your Workers site has its custom build settings, you can bring your prebuilt assets to Pages with . In addition, you can serve your website’s assets right to the Cloudflare global network by either using the or the drag and drop option.
These options allow you to create and name a new project from the CLI or dashboard. After your project deployment is complete, you can set the custom domain by following the steps to your Pages project.
Cleaning up your old application and assigning the domain
After you have deployed your Pages application, to delete your Worker:
- Log in to the and select your account.
- Go to Workers & Pages and in Overview, select your Worker.
- Go to Manage service > Delete.
With your Workers application removed, requests will go to your Pages application. You have successfully migrated your Workers Sites project to Cloudflare Pages by completing this guide.