Same-host vs CDN
Default same-host URLs vs public_base_url rewrite modes.
Default: same-host
With public_base_url empty (default):
- WordPress keeps advertising
/wp-content/uploads/...on your site domain. - If the file exists locally, PHP/nginx serves it as usual.
- If missing, the plugin streams the object from S3 (response header
X-WP-To-S3: 1). - Optional:
WP_TO_S3_REDIRECT_MISSINGfor a 302 to a public or presigned S3 URL. - You can put Cloudflare (or similar) in front of the site to cache same-host media.
No forced rewrite to provider hostnames.
Optional: public_base_url
When WP_TO_S3_PUBLIC_BASE_URL (or Media → WP to S3 → Public base URL) is set:
wp_get_attachment_url, imagesrc, andsrcsetrewrite to that base + the same relative path._wp_attached_filemetadata is not changed.- Browser requests typically hit the CDN/bucket directly; the PHP stream path is unused for those URLs.
- Same-host paths still work if something requests them and the local file is missing (Serve still registered).
Example:
Uploads base: https://example.com/wp-content/uploads
public_base: https://cdn.example.com/media
Attachment: https://cdn.example.com/media/2020/03/foo.jpg
Object key: 2020/03/foo.jpg (plus optional prefix)
Historic post content
Old post HTML may still contain absolute https://example.com/wp-content/uploads/... links.
- Default: do nothing (same-host URLs remain correct forever if you stay on same-host mode).
- When using CDN: enable Content rewrite toggle in Settings, then use Tools → Dry-run then Apply to rewrite post/page content only.
- Content rewrite never runs automatically.
Choosing a mode
| Goal | Recommendation |
|---|---|
| Simplest cutover, no DNS/CDN work | Same-host stream (default) |
| Offload bandwidth from origin | Same-host + CDN caching your domain |
| Direct public bucket or custom media domain | Set public_base_url (+ optional content rewrite) |