Subdomains and subdirectories
Last updated Apr 16, 2026
Run APO on a subdomain
After you enable APO, you configure it to run on the subdomain that uses WordPress. For example, if you have a website called www.mysite.com which includes a subdomain running WordPress called shop.mysite.com, you would configure APO to run on the shop.mysite.com subdomain.
- Install version 4.4.0 or later of the Cloudflare WordPress plugin.
- Log in using Cloudflare API token or Global key.
- Enable APO. The subdomain displays in the list of hostnames in the card.
- Repeat the process for each subdomain to enable APO.
By default, APO runs on the apex domain (also known as "root domain" or "naked domain"). If you choose to run APO on a subdomain, the apex domain is automatically disabled. To run APO on a subdomain and the apex domain, upgrade the WordPress plugin to version 4.4.0 or later on the apex domain and re-enable APO.
Run APO on a subdirectory
After you enable APO, you configure it to run on the subdirectory that uses WordPress. For example, if you have a website called www.mysite.com which includes a subdirectory running WordPress called mysite.com/shop, you would configure APO to run on the mysite.com domain.
- Install the Cloudflare WordPress plugin.
- Add your Cloudflare API Token.
- Activate APO.
Repeat steps 1 and 2 for each subdirectory to activate the WordPress plugin for automatic cache purging.
Run APO only on a subdirectory
If you choose to run APO only on a subdirectory, the rest of the domain should be configured to bypass APO. You can bypass APO in one of two ways.
Use the cf-edge-cache response header
The cf-edge-cache: no-cache instructs the APO service to bypass caching for non-WordPress parts of the site. You can implement this option with Cloudflare Workers using the example below.
export default {
async fetch(request, env, ctx) {
const originalResponse = await fetch(request);
// Response properties are immutable. To change them, construct a new Response object.
const response = new Response(originalResponse.body, originalResponse);
// Response headers can be modified through the headers `set` method.
response.headers.set("cf-edge-cache", "no-cache");
return response;
},
};
Use Cache Rules
Create a cache rule to exclude non-WordPress portions of the site from caching using Cache eligibility: Bypass cache. This option disables all caching, including static assets for those paths. As a result, we recommend disabling APO via the response header.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/automatic-platform-optimization/reference/subdomain-subdirectories/#page","headline":"Subdomains and subdirectories","description":"Run APO on WordPress subdomains and subdirectory installations.","url":"https://developers.cloudflare.com/automatic-platform-optimization/reference/subdomain-subdirectories/","inLanguage":"en","image":"https://developers.cloudflare.com/automatic-platform-optimization/reference/subdomain-subdirectories/og.png?v=3b3dd56b01fee863","dateModified":"2026-04-16","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["WordPress","JavaScript"]}
description: Resolve common APO issues including plugin detection and stale content. title: Troubleshooting image: https://developers.cloudflare.com/automatic-platform-optimization/troubleshooting/og.png?v=23aa30c09b7f3723
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/automatic-platform-optimization/llms.txt
Use this file to discover all available pages before exploring further.
Docs