Subdomains and subdirectories
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.
addEventListener('fetch', event => { event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) { /** * Response properties are immutable. To change them, construct a new * Response object. Response headers can be modified through the headers `set` method. */ const originalResponse = await fetch(request);
let response = new Response(originalResponse.body, originalResponse);
// Add a header using set method response.headers.set('cf-edge-cache', 'no-cache');
return response;
}
Use Page Rules
Use Page Rules to exclude non-WordPress portions of the site from caching using Cache Level: Bypass. This option disables all caching, including static assets for those paths. As a result, we recommend disabling APO via the response header.